uli101_week11_practice

.docx

School

Seneca College *

*We aren’t endorsed by this school

Course

101

Subject

Computer Science

Date

Dec 6, 2023

Type

docx

Pages

5

Uploaded by ChancellorDragonfly3067

Report
ULI101 Linux Command Practice 11 (Using the sed and awk Utilities) _____________________________________________________________________________ Instructions: Write the answer to each question below the question in the space provided. You can “wrap-around” the answer on separate lines if you need more space. Part A: Display Results from Using the sed Utility Note the contents from the following tab-delimited file called ~murray.saul/uli101/stuff.txt: (this file pathname exists for checking your work) Line one. This is the second line. This is the third. This is line four. Five. Line six follows Followed by 7 Now line 8 and line nine Finally, line 10 Write the results of each of the following Linux commands for the above-mentioned file. 1. sed -n '3,6 p' ~murray.saul/uli101/stuff.txt print line 3 to line 6 2. sed '4 q' ~murray.saul/uli101/stuff.txt print the first 4 lines and then quit 3. sed '/the/ d' ~murray.saul/uli101/stuff.txt delete line that have the word the 1 PAGE
ULI101 Linux Command Practice 11 (Using the sed and awk Utilities) _____________________________________________________________________________ 4. sed 's/line/NUMBER/g' ~murray.saul/uli101/stuff.txt substitute line with NUMBER Part B: Writing Linux Commands Using the sed Utility Write a single Linux command to perform the specified tasks for each of the following questions. 1. Write a Linux sed command to display only lines 5 to 9 for the file: ~murray.saul/uli101/stuff.txt sed -n ‘5,9 p’ ~ murray.saul/uli101/stuff.txt 2. Write a Linux sed command to display only lines the begin the pattern “and” for the file: ~murray.saul/uli101/stuff.txt sed -n ‘/^and/p’ ~murray.saul/uli101/stuff.txt 3. Write a Linux sed command to display only lines that end with a digit for the file: ~murray.saul/uli101/stuff.txt sed -n ‘/[0-9]$/p’ ~murray.saul/uli101/stuff.txt 4. Write a Linux sed command to save lines that match the pattern “line” (upper or lowercase) for the file: ~murray.saul/uli101/stuff.txt and save results (overwriting previous contents) to: ~/results.txt sed -n ‘/[L]line/’ ~murray.saul/uli101/stuff.txt > ~/results.txt 2 PAGE
ULI101 Linux Command Practice 11 (Using the sed and awk Utilities) _____________________________________________________________________________ Part C: Writing Linux Commands Using the awk Utility Note the contents from the following tab-delimited file called ~murray.saul/uli101/stuff.txt: (this file pathname exists for checking your work) Line one. This is the second line. This is the third. This is line four. Five. Line six follows Followed by 7 Now line 8 and line nine Finally, line 10 Write the results of each of the following Linux commands for the above-mentioned file. 5. awk ‘NR == 3 {print}’ ~murray.saul/uli101/stuff.txt print the 3 rd line 6. awk ‘NR >= 2 && NR <= 5 {print}’ ~murray.saul/uli101/stuff.txt print the line 2 nd to line 5 th 7. awk ‘$1 ~ /This/ {print $2}’ ~murray.saul/uli101/stuff.txt field 1 => This => print field 2 8. awk ‘$1 ~ /This/ {print $3,$2}’ ~murray.saul/uli101/stuff.txt 3 PAGE
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help