Re: Simplest sed

From: Jochen Cichon ([email protected])
Date: Wed Nov 22 2000 - 09:46:56 CET


> Hi all,
> I have a blind eyed question: while I have plenty of experience with awk,
> I have never ever used sed. How do I make sed replace one thing by
> another (surely, that's what you use sed for?)? For example, how do I
> replace all occurences of #include <old.h> by #include <new.h> in a
> c-program?
> Thanks. There's always a first time. Mine is today.
> P.S. I tried the sed-man-page, of course, but it was hardly helpful

Hm. OK sed :)

cat file | sed 's/old.h/new.h/g' >newfile

Means search/replace old.h to new.h, the g means global (so more than one time)
Of you have to do that on more than one file.
--------finder---------------
#!/bin/sh
for i in $*
do
        cp $i $i.bak
        cat $i.bak | sed 's/old.h/new.h/g' >$i
done
-----------------------------
With that you can call it with
        finder file1 file2 file3
or
        finder *.c
It does at first a Backup :) (Murphy: If something can go wrong, it does!)
After that do replace

But if you use vi ( Don't call SIX Editor :) )
you can type the sed command in command mode.
Just type
        :1,$s/old.h/new.h/g
Means:
        from Line 1 to End of File search/replace old.h to new.h global

Perfect. Just loving VI

Ciao Jochen

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]



This archive was generated by hypermail 2.1.6 : Sat Feb 08 2003 - 15:27:16 CET