I'm new to sed
, I'm trying to insert the content of a BFile into the file AFile, BEFORE a pattern (in AFile)
Hereafter's what I've tried :
sed -i '/blah Blah/r BFile' AFile
: it's inserting the content of BFile AFTER the pattern in AFile.
sed -i '/blah Blah/i BFile' AFile
: it's inserting the string 'BFile' BEFORE the pattern in AFile.
... hmmm
I'm conscious it's because of a wrong comprehension of regexp or sed
: I can't understand how the /i
and /r
work here... I can't find any help in sed --help
Anyone understanding my point ?
Regards,
Stan
This might work for you (GNU sed):
sed $'/blah Blah/{e cat Bfile\n}' AFile
or:
sed -e 'N;/\n.*blah Blah/{r Bfile' -e '};P;D' AFile
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句