Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Linux Awk Script file coding 5. Write an awk script file that will insert the co

ID: 3723409 • Letter: L

Question

Linux Awk Script file coding

5. Write an awk script file that will insert the contents of the /etc/passwd

file between lines 14 and 15 of the input.

6. Write an awk script file that will sort lines 7 through 26 of the input into

aphabetical order.

7. Write an awk script file that will add a "#" character to the start of every

line that does not already start with one.

8. Write an awk script file that will append all lines of the /etc/passwd file

that contain the word "STUDENT" to the input

9. Write an awk script file that will move the last word of each line to the

start of the line.

10. Write an awk script file that will add the line number to the beginning of

each line of input.

Explanation / Answer

Dear Student,

5. Syntax is: sed -i <line number>r<file-1> <file2->

command is: sed -i 14r/etc/passwd input_file.txt.

"i" will insert contents of "/etc/passwd" file to input_file.txt(specifify your input file).

6. head -n 6 file_name.txt && sed -n '7,26p' file_name.txt|sort && sed -n '27,$p' file_name.txt

3 parts in above command:

head -n 6 file_name.txt : Simply prints first 6 lines of input file

sed -n '7,26p' file_name.txt|sort : reads 7 to 26 lines from input file and sort the lines in alphabetical order then prints.

sed -n '27,$p' file_name.txt: Prints lines from 27 onwards from input file.

7. awk '{print "#"$0}' inputfile_name.txt

8. awk '$0 ~ /STUDENT/{print}' /etc/passwd >>input

9. awk '{print $NF,$0}' anaconda-ks.cfg | awk '{$NF=""}1'

10.  awk '{print NR-1 "," $0}' inputfile

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote