Create the following file as sed.lab: unix is great os. unix is opensource. unix
ID: 3817445 • Letter: C
Question
Create the following file as sed.lab: unix is great os. unix is opensource. unix is free os. learn operating system. unixlinux which one you choose. 1. Replace ‘unix’ with ‘linux’. Q1: what command would you use? Enter the command. How many instances of ‘unix’ are replaced with ‘linux? 2. Replace only the third (3rd) instance of ‘unix’ with ‘linux’. Q2: what command would you use? 3. Try sed ’s/unix/linux/g’ sed.lab. Q3: how is this different than the prior commands? 4. Replace ‘unix’ with ‘linux’ but only on line 3. Q4: what command would you use? Enter the command. Did it work? 5. Add a new line, ‘Actually Windows is best’ after the second line. Q5: what command would you use? Enter the command. Did it work? Awk 1. Create a file named awker.txt and enter the following content: My name is awker. Hulkamania ran wild all over me so now I’m as flat as a pancake. 2. Look at the following script: awk < awker.txt ‘{ print $2, $3 }’ Q1: What do you think this script will do? Q2: Enter the command. What happened? 3. Look at the following script: echo 5 4 | awk ‘{ print $1 + $3 }’ Q3: What do you think this script will do? Q4: Enter the command. What was the output? Q5: How could we change the script so that the output will be 9? 4. Back to awker.txt… Q6: What script would print just the first field of each row (also we could say the first column)?
Explanation / Answer
As there are multiple questions, I am answering the first 5 questions
Considering the lines are written in a file called "sed.lab"
Q1> Ans:
Command : >sed 's/unix/linux/' sed.lab
This will replace the first occurance of "unix" with "linux"
But if we use this command >sed 's/unix/linux/g' sed.lab, It will replace all the occurances
Q2> Ans:
Command : >sed 's/unix/linux/3' sed.lab , This will replace the 3rd occurance of "unix" with "linux"
Q3> Ans:
If we use 's/unix/linux/g’ sed.lab command, it will replace all the occurances of "unix" with "linux". It is already mentioned in the earlier answer.
Q4> Ans:
Command: '3 s/unix/linux/g’ sed.lab, This will replace all the occurances of "unix" with "linux" in line number 3
Q5> Ans:
Command: >sed -i '3iActually Windows is best' sed.lab . This will insert the sentence after the second line.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.