Question

In: Computer Science

Unix command lines. A) Assume that your current working directory is NOT the same as your...

Unix command lines.

A) Assume that your current working directory is NOT the same as your home directory. Print all file and subdirectory names of your home directory into a file named file2.

B) Copy the text from line 11 to line 20 of a given file input.txt and append the copied text at the end of the file output.txt. (Assume that the file input.txt contains more than 20 lines of text contents)

C) Count and display the total number of words in ALL files in the current working directory whose name end with “.txt”

D) Count the number of lines where the word “foo” appears in a given file bar.txt

Solutions

Expert Solution

A. Command : ls -l > files.txt and find . -ls > file2.txt

Explanation : ls command is used to list all the files in the directory. -l option provides one to give all the information. > is used as redirection operator all the output generated previously is stored in the given files.txt.

B. Command : sed -n -e '11,20p' input.txt >> output.txt

Explanation : Sed is a powerful text stream editor. One can do insertion, deletion, search it also support regular expressions. Using -n -e option one can able to copy the specified lines of the provided input file. >> is used for concatenation of the files input. The results are copied at the end of the output.txt file.


C.Command : find *.txt -type f -exec wc -w {} \; | awk '{total += $1} END{print total}'

Explanation : Find command is used to search the files based on the command one provides. Here we have provided *.txt which says that to find all the .txt files in the current directory. With that using wc -w we will compute the wordcount and store them in the buffer array. Pipe command (|) is used to connect two or more commands where the current command output acts as the input to the next command. Awk is line-oriented command which is used to execute the things without the intervention of complex functions. It is famously used for writing effective programs in the form of statements. $1 says that the word-1 of the particular there the number of words in a file is calculated. The aggregation is calculated using awk and then prints the total number of words in ALL the .txt ( text ) files.

D.Command : grep "foo" bar.txt | wc -l

Explanation : Grep is the unix command used to fiter the search using certain pattern. Here “foo” is our pattern to be searched in bar.txt file. As we already discussed pipe command (|) is used to connect two or more commands where the current command output acts as the input to the next command. using wc one can determine the word count -l is the option with which number of lines found out.


Related Solutions

1. What command is used to change the current working directory at the command line?
1. What command is used to change the current working directory at the command line?
Unix ramdom question. How do you display a list of files in your current directory, sorted...
Unix ramdom question. How do you display a list of files in your current directory, sorted by file size with the largest files at the top.
UNIX/LINUX SCRIPT: Create a named directory and verify that the directory is there by listing all...
UNIX/LINUX SCRIPT: Create a named directory and verify that the directory is there by listing all its contents. Write a shell script to validate password strength. Here are a few assumptions for the password string.   Length – a minimum of 8 characters. • Contain alphabets , numbers , and @ # $ % & * symbols. • Include both the small and capital case letters. give a prompt of Y or N to try another password and displays an error...
Move the file “nfile2” into the “unix” directory. Copy the file “nfile1” into the “java” directory....
Move the file “nfile2” into the “unix” directory. Copy the file “nfile1” into the “java” directory. Show how you would create the files “test1”, “test2”, & “test3” in the “test” directory to ensure that they have the same file creation date/time. From the ~ folder, use the * and then the [ ] wildcard procedures to list all the files in the “test” directory. From the directory structure above, give an example of a relative path & an absolute path....
1. Compare the Unix directory and the windows directory and answer the following: a. Match 3...
1. Compare the Unix directory and the windows directory and answer the following: a. Match 3 Unix directories to a Windows directory that is similar in function. Briefly describe their similarities and differences. b. Find a directory in Unix that appears to have no equivalent in Windows. What does it do? c. Find a directory in Windows that appears to have no equivalent in Unix. What does it do?
Demonstrate your grasp of the Unix file system by constructing a directory structure as follows: In...
Demonstrate your grasp of the Unix file system by constructing a directory structure as follows: In your home ( ~ ) directory, create a directory named “UnixCourse”. This directory will be used in the remaining assignments of this course, as well as this one. Several of the commands that you will issue in this course will examine files in this directory and, in some cases, send me a listing of those files or even copies of those files for grading...
What are the permissions for your home directory set by your system administrator? What command did...
What are the permissions for your home directory set by your system administrator? What command did you use to answer the question? Show your session.
unix/Linux Create a tar command using the man command and the link referred to in To...
unix/Linux Create a tar command using the man command and the link referred to in To Practice and Explore: Text File Utilities #9. Preliminaries Use the man pages to learn more about tar Review the links referred to in To Practice and Explore: Text File Utilities #9 to see examples of using tar command Perform Use tar "to stuff" three files and then "unstuff" them into a new directory. Include the -v option. Task ll to show the original 3...
please use linux or unix to complete Diff command The diff command displays differences between two...
please use linux or unix to complete Diff command The diff command displays differences between two files on a line-by-line basis. It displays the differences as instructions that you can use to edit one of the files ( using the vi editor) to make it the same as the other. When you use diff, it produces a series of lines containing Append (a), Delete (d), and Change (c) instructions. Each of these lines is followed by the lines from the...
Linux Use touch to create a file in your working directory called PutFileHere this is a...
Linux Use touch to create a file in your working directory called PutFileHere this is a linux question i acidentally put javascript when i first submitted it
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT