I have a text in a single file
Quiz
Worker(Thomas) works in ..........
Worker(Alfred) works in ..........
Worker(Albert) works in ..........
Answer
Worker(Thomas) works for company(google)
Worker(Alfred) works for company(apple)
Worker(Albert) works for company(Microsoft)
I wish to replace the empty dotted lines in "Quiz" from information given in "Answer" by using sed based text search, matching and replacement.
I suggest using
awk
for this task. Assuming you have two separate filesQuiz
andAnswer
in the same directory,cd
into that directory and run the following command in the terminal:A new file named
Answered_Quiz
will be created in the same directory and it will contain the desired result.If all the lines are in one file, you can split it first:
run the following command replacing
FileName
with your text file name:to make the Quiz file.
then run the following command replacing
FileName
with your text file name:to get the Answer file. Your original file will not be affected
Or if all the lines are in one file and you prefer not to split the file, use the following code in a script file (or you can just copy and paste it in the terminal and press Enter) from within the same directory:
A new file named Answered_Quiz will be created in the same directory and it will contain the desired result.
Best of luck