questions & answers
Write a command to replace the word "bad" with "good" in file: "filename.txt" - ANSWERSsed
's/bad/good/' < filename.txt
Write a command to replace the word "apple" with "(apple)" in filename.txt - ANSWERSsed
's/apple/(&)/' < filename.txt
Write a command to switch the two consecutive words "apple" and "mango" in filename.txt -
ANSWERSsed 's/\(apple\) \(mango\)/\2 \1/' < filename.txt
Write a command to replace the nth occurrence of the word "bat" with "ball" in f.txt -
ANSWERSsed 's/bat/ball/n' < f.txt
Write a command to remove all the occurrences of the word "jhon" except the first one in a line
with in the entire f.txt - ANSWERSsed 's/john//2g' < f.txt
Write a command to remove the first number on line 5 in f.txt - ANSWERSsed '5 s/[0-9][0-9]*//'
< f.txt
Write a command to replace the word "gum" with "drum" in the first 100 lines of f.txt -
ANSWERSsed '1,100 s/gum/drum/' < f.txt
write a command to replace the word "lite" with "light" from 100th line to last line in f.txt -
ANSWERSsed '100,$ s/lite/light/' < f.txt