questions unix, help using putty. **please show work using a program** with all
ID: 3733632 • Letter: Q
Question
questions unix, help using putty. **please show work using a program** with all questions answered (if possible), I'll rate. so I can Have a understanding really helps
Commands to study to answer this question: tail, head, cmp, diff, comm, uniq, touch,
umask, grep, vi, cat, ls, and echo
Two files can be compared using cmp command and diff command depending on requirements.
In order to do this question, create two files with 12 or more names with one name in each line. Make sure that some names in the two files are same and some are different. Ensure that there are few consecutive lines with identical names (duplicate lines) in each file. Also, make sure that some of the names are the same in both files.
Create these two files before issuing the script command to answer this question.
1) Display the content of each file, one at a time
2) Compare the two files using cmp command
3) Find the differences between using diff command
4) Sort first file and store the result by redirecting the output to a file as sorted
5) Sort second file and store the result by redirecting the output to another file as sorted
Two files can also be compared comm command. There are differences between cmp, diff and comm commands. Read about them and understand the differences.
6) Compare the two sorted files using comm command
7) Display ONLY the bottom 5 lines of the first file
8) Display the top few lines of the second file using the default line count, that is, without using any option in the command. Count and find how many lines it displays by default
9) Issue appropriate command to display the content of first file removing consecutive duplicate lines
10) Create the file hw2before_setting_umask using touchcommand
11) The umask command can be used to set or change the default file permissions to be set when a new file is created. Issue umask 600 command
12) Create the file hw2after_setting_umask using touchcommand
13) Display the file permissions set on hw2before_setting_umask and hw2after_setting_umask
14) Using echo command answer what permissions were removed for the owner due to the above umask command
The grep command can be used to search for a string in one or more files. When the line with the string is found, it is displayed. Check this by issuing the following grep commands.
15) Issue a grep command on hw2test1 with a name that exists in hw2test1.
16) Issue a grep command on hw2test[12] with a name that exists in both files (hw2test1 and hw2test2).
17) Issue a grep command on hw2test[12] with a name that does not exist in both files.
18) What difference you see between (16) and (17) by Observing the output of above three grep commands
Explanation / Answer
Two names Txt files:
f1.txt:
Hello
World
Loren
Pierre
Edward
Lakme
Reli
Danny
Justin
Justin
David
Query
Mary
f2.txt:
Ram
Sita
Hari
Justin
Mary
Mary
Query
Hello
Different
Oswald
Doremon
Pokemon
HaoYang
Donald
1. "cat f1.txt" for displaying file f1.txt
"cat f2.txt" for displaying file f2.txt
cat f1.txt f2.txt for displaying files together.
2. cmp f1.txt f2.txt for comparing two files
3. diff f1.txt f2.txt for finding the difference between two files
4. sort f1.txt > sortedf1.txt for sorting the file and storing the content into file named as "sortedf1.txt"
5. sort f2.txt > sortedf2.txt for sorting the file and storing the content into file named as "sortedf2.txt"
Differences between cmp, diff, comm
cmp: Compare files byte by byte. Gives the output as difference found at line and character number.
diff: Compare files line by line. Gives the output as the lines which differ in files
comm: The comm utility reads file1 and file2, which should be sorted lexically and produces three text columns as output: lines only in file1; lines only in file2; and lines in both files.
6. comm sortedf1.txt sortedf2.txt compares two sorted files and gives the differences and comman things.
7. tail -n 5 f1.txt" or tail -5 f1.txt Displays last five lines of f1.txt
8. head f2.txt Displays default top 10 lines of file f2.txt
9. uniq f1.txt Displays only unique lines present in file. Removes duplicated lines.
10. touch hw2before_setting_umask
11. umask 600
12. touch hw2after_setting_umask
13. ls -l hw2before_setting_umask hw2after_setting_umask displays file permissions in first column
15. grep Hello f1.txt
16. grep Justin f[12].txt
17. grep James f[12].txt
18. The difference between the outputs is that, in 16th command we see the file names along with the word present in those files. While in 17th command we don't find any output. It simply exits.
NOTE: Please rename the file names f1.txt to hw2test1.txt and f2.txt to hw2test2.txt and run all the commands for renamed files.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.