4

I have file1 & file2, I want to cat file1 into file2 after match of 22 pattern.
Can I do it with cat or I need to go for awk or sed

file1

aa
bb
cc

file2

11
22
33
44

Resultant file2

11
22
aa
bb
cc
33
44

2 Answers 2

7

With sed:

sed -e '/22/r file1' file2
2

For completeness, here is an awk solution:

$ awk '{print;} /22/{system("cat file1");}' file2
11
22
aa
bb
cc
33
44
1
  • awk '1;/22/{system("cat file1")}' for shorter version.
    – cuonglm
    Jun 4, 2015 at 6:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.