Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Sed question

223 views
Skip to first unread message

Walter Gray

unread,
Feb 10, 1999, 3:00:00 AM2/10/99
to
In article <36c0f...@news.iglou.com>, bma...@iglou.com writes:
:
:
:On 1999-02-09 wag...@taz.dra.hmg.gb said:
: >When I wanted a filter/editor I took a look at sed and when
: >I had finished laughing I wrote my own, which I call "ef".
: >so; inputfile | ef cccLW > outputfile
: >simple enuf?
:
:Where can I get it?
:
:Net-Tamer V 1.08X - Test Drive
:

Email if you want a copy to play with. I could use
some constructive/destructive criticism on it.


Walter

Disclaimer: My employer is not responsible for this stuff.

Max Kliche

unread,
Feb 11, 1999, 3:00:00 AM2/11/99
to
Hallo,
Little ? problem with sed

I have a file like that

text
+++
text
+++
text
+++

and so on.
Now I wnat to replace the first of the +++ whith the content
of another file like this:
line1
line2
line3

Result should be:
text
line1
line2
line3
text
+++
text

I tried to use sed s/"+++"/( cat file2 )/ file1 but it doesn´t work.
How can I do this on an other way ?

Best regards, Max

sharon...@icomverse.com

unread,
Feb 14, 1999, 3:00:00 AM2/14/99
to
Dear Max !

I also couldn't perform this with sed. Nevertheless "ed" did the job:

First assume that file2 is the file whose contents are to be inserted in file1
replacing the first line that contains +++ in the beginning of a line:

In ksh the following worked:

a one liner :

echo "/^+++/\nc\n$(<file2)\n.\nw\nq" | ed file1

or, using a here document:

ed file1 <<-EOF
/^+++/
c
$(<file2)
.
w
q
EOF

In sh the following one liner worked for me :

echo "/^+++/\nc\n`cat file2`\n.\nw\nq" | ed file1

or, using a here document :

ed file1 <<-EOF
/^+++/
c
`cat file2`
.
w
q
EOF


In csh the one liner won't work, but the here document (identical to the sh
one) works. Both of the commands that work in sh work also in ksh, but the
$(<file2) command is much more efficient than `cat file2`.


Best regards, Sharon.


In article <36C212F3...@dagobert.falkenstr.de>,

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own

0 new messages