Re: replace the string in all the files in the directory
- From: Rafael Almeida <rafaelc@xxxxxxxxxxx>
- Date: Thu, 30 Nov 2006 02:40:07 -0200
On Wed, 29 Nov 2006 23:43:43 +0100
Pascal Bourguignon <pjb@xxxxxxxxxxxxxxxxx> wrote:
for f in *.c ; do
cp ${f} ${f}~ && sed -e 's/string/replacement/g' < ${f}~ > ${f}
done
cp is used instead of mv, to keep the owner and access rights of ${f}.
&& is used to avoid overwritting the original file if the copy
didn't complete successfully.
Usually, you don't substitute strings, but tokens or words; read
man sed and man 7 regex and use \<word\> in the regexp!
I think he wanted to replace a string such as
"I'm a C literal string!"
to something else. So sed probably won't work for him, as a string may
span through several lines.
.
- References:
- replace the string in all the files in the directory
- From: qianz99
- Re: replace the string in all the files in the directory
- From: Pascal Bourguignon
- replace the string in all the files in the directory
- Prev by Date: Re: system() without waiting
- Next by Date: Storage problem in Unix
- Previous by thread: Re: replace the string in all the files in the directory
- Next by thread: Re: replace the string in all the files in the directory
- Index(es):
Relevant Pages
|