Discussion:
Need help with reading in a fileto replace a line, using sed
Daniel
2013-03-11 00:18:30 UTC
Permalink
That's clever and interesting how you split { and } into two different -e options. Here is another possible solution:

sed -e '/xxxxx/r textfile2' -e '//d' textfile1

I like the 'r' command. What I find weird about 'r' is how the filename cannot be terminated. I know ";" is a legal character in a Unix file name. But it's certainly not a recommended character, seems a really bad idea to put ";" in a file name. So I wonder if any possibility the following could be make legal, to let ";" tell sed to terminate the file name:

sed '/xxxxx/{ r textfile2; d }' textfile1

The same might apply to other commands / flags that use a filename.
Hi.  I have a shell script that uses ed to replace a line in file
textfile1
containing the pattern xxxxx with the contents of a file (textfile2).
It does this by locating the line, deleting the line, then reading in
textfile2.
The only concern with textfile2 is that it might also contain the same
pattern (xxxxx).
textfile1 will only have this pattern (xxxxx) occur once.
I am wondering if someone knows a way to do this same thing using sed.
Remember that textfile2 might also contain the pattern xxxxx.
sed -e '/xxxxx/{ r textfile2' -e 'd; }' textfile1
--
D.
Loading...