Add the contents of one file into other based upon a pattern match.
File1 Contents:
line1-file1 "1"
line2-file1 "2" l
ine3-file1 "3"
line4-file1 "4"
File2 Contents:
line1-file2 "25"
line2-file2 "24"
Pointer-file2 "23"
line4-file2 "22"
line5-file2 "21"
After the execution of perl/shell script,
File 2 content should become
line1-file2 "25"
line2-file2 "24"
Pointer-file2 "23"
line1-file1 "1"
line2-file1 "2" l
line3-file1 "3"
line4-file1 "4"
line4-file2 "22"
line5-file2 "21"
Solution :
sed -i '/Pointer-file2/r file1' file2
0 comments: