points for ahoffmann

xoxomos
xoxomos used Ask the Experts™
on
I have a file that contains
aaaaa
bbbbb
aaaaa
eeeee
begin junk
1234
5678
9012
3456

end junk
eeee
llll
bbbb
qqqq
I want to look for junk.
 Once i locate 'begin junk'
 i want to replace everything
between begin junk and end junk
 with the contents of a file filex

and the solutions:



perl already done, here as gawk:

gawk '/begin junk/{s=1}/end junk/{s=0;while(getline<"filex"){print};next;}(s==0){print}' file


# .. or simple sed:
sed -ne '/end junk/{' -e 'r filex' -e n -e '}' -e '/begin junk/{' -e n -e '}' -e p file
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
do you mean that you're satisfied with my single-command-line solution too, rather than the other suggested ones?

Well, that'S generous. Thanks.
ping xoxomos ;-)

Author

Commented:
been a while, but i think it was the best one!
pong ;-)

Thanks xoxomos.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial