Results 1 to 2 of 2
Hi,
I have a file, say abc.txt, whit some text lines.
The I have a second file, say 123.txt where at a certain point one can read "WORD".
I would ...
- 02-05-2010 #1Just Joined!
- Join Date
- Feb 2010
- Posts
- 8
append file content in another file when pattern matches
Hi,
I have a file, say abc.txt, whit some text lines.
The I have a second file, say 123.txt where at a certain point one can read "WORD".
I would like to append the whole content of abc.txt (as it appears in abc.txt) in the line after "WORD".
I was thinking something like
sed '/WORD/ a\ abc.txt content' 123.txt. Is it silly?!
Thaks for your help.
Regards
- 02-06-2010 #2Linux User
- Join Date
- Jan 2007
- Location
- cleveland
- Posts
- 448
try breaking abc.txt apart into 2 files at 'WORD' then use "cat"
to insert 123.txt--like this
sed '/WORD/ q' <abc.txt >first.txt
where first.txt contains all lines from abc.txt up to and including
the line with 'WORD' on it
now make another file "second.txt" with the remainder of abc.txt
comm -3 abc.txt first.txt >second.txt
then:
cat 123.txt >>first.txt
cat second.txt >>first.txt
should leave first.txt with the required result.the sun is new every day (heraclitus)


Reply With Quote
