UNIX COMMANDS
Task B
Create a one-line command, using the famous.dat file, to add the
word " STREET" to the address, for all who live on 2nd or
3rd.
For example: "2nd" becomes "2nd STREET" and "3rd" becomes "3rd
STREET".
Display only the first 9 lines.
Hint: Use 2 sed statements with pipes.
Task
C
Display all lines in famous.dat that end in 0 or 1, and have a 1 in
the 3rd from the last column.
For example lines ending in 120 and 131 would be displayed.
Task
D
Display all lines in famous.dat that have only 4 or 5 or 6 or 7 or
9 in the zip code.
Hint: this is the same as NOT 0 or 1 or 2 or 3 or
8.
Task
E
Using only the grep command, search all files with names that end
in .htm followed by anything (use .htm*) under the
$HOME/public_html directory and display any lines that contain body
tags (containing '<body>')
No other output should be displayed even if there is no public_html
directory or no file
Hint: use two command arguments and 2>
Please try posting the other questions separately if you need an answer to them. I can provide answers to only the first part in the allotted time and as per company policy, I am allowed to answer only one task. However, I am providing you with a solution to the 2nd task as well. Give me an up vote if you like my answer.
TASK B :
head -n 9 famous.dat | sed -r 's/(2nd|3rd)/\1 STREET/g' //This will add street only to first 9 lines
sed -r 's/(2nd|3rd)/\1 STREET/g' famous.dat | head -n 9 famous.dat //this will add street to all the lines and will display 9 lines after that.
Task C:
grep '1.[01]$' famous.dat
Get Answers For Free
Most questions answered within 1 hours.