FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Red Hat Linux

 
 
LinkBack Thread Tools
 
Old 10-24-2008, 06:56 PM
"Mad Unix"
 
Default replace string

i need your feedback about this command, it should find a string in
multiple html files in a directory and replace it with a different
string...

find /dir -name "*.html" -exec sed i 's/"old"/"new"/g' {} ;

Thx.

--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
 
Old 10-24-2008, 10:31 PM
Cameron Simpson
 
Default replace string

On 24Oct2008 23:26, Mad Unix <madunix@gmail.com> wrote:
| i need your feedback about this command, it should find a string in
| multiple html files in a directory and replace it with a different
| string...
|
| find /dir -name "*.html" -exec sed i 's/"old"/"new"/g' {} ;

Well, yeah, if you had spelt the "-i" option correctly.
But if you have hard links in there (unlikely, but some people do)
it will break them if it modifies the file.

I have no idea what kind of "feedback" you were after...
--
Cameron Simpson <cs@zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
 
Old 10-25-2008, 08:13 PM
Yong Huang
 
Default replace string

> From: "Mad Unix" <madunix@gmail.com>
>
> i need your feedback about this command, it should find a
> string in
> multiple html files in a directory and replace it with a
> different
> string...
>
> find /dir -name "*.html" -exec sed i 's/"old"/"new"/g' {} ;
>
> Thx.

Even if you get your sed command right, that won't do in-place replacement, because if you use sed, the result has to be saved to a different file and you mv that file to overwrite your original file.

Perl's in-place edit helps in your case:

find /dir -name "*.html" -exec perl -pi -e 's/old/new/g' {} ;

Yong Huang




--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
 
Old 10-26-2008, 12:33 AM
Cameron Simpson
 
Default replace string

On 25Oct2008 13:13, Yong Huang <yong321@yahoo.com> wrote:
| > From: "Mad Unix" <madunix@gmail.com>
| > find /dir -name "*.html" -exec sed i 's/"old"/"new"/g' {} ;
|
| Even if you get your sed command right, that won't do in-place
| replacement, because if you use sed, the result has to be saved to a
| different file and you mv that file to overwrite your original file.

He is trying to use GNU sed's -i option, which does the same kind of thing as
Perl's -i (in place edit) option, with the same often-undesirable hard link
breakage.
--
Cameron Simpson <cs@zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

Microsoft is not the ANSWER.
Microsoft is the QUESTION,
and the ANSWER is NO! - Roland.Giersig@aut.alcatel.at

--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
 
Old 10-26-2008, 01:05 AM
Yong Huang
 
Default replace string

--- On Sat, 10/25/08, Cameron Simpson <cs@zip.com.au> wrote:

> From: Cameron Simpson <cs@zip.com.au>
> Subject: Re: replace string
> To: yong321@yahoo.com, "General Red Hat Linux discussion list" <redhat-list@redhat.com>
> Date: Saturday, October 25, 2008, 7:33 PM
> On 25Oct2008 13:13, Yong Huang <yong321@yahoo.com>
> wrote:
> | > From: "Mad Unix" <madunix@gmail.com>
> | > find /dir -name "*.html" -exec sed i
> 's/"old"/"new"/g' {} ;
> |
> | Even if you get your sed command right, that won't do
> in-place
> | replacement, because if you use sed, the result has to be
> saved to a
> | different file and you mv that file to overwrite your
> original file.
>
> He is trying to use GNU sed's -i option, which does the
> same kind of thing as
> Perl's -i (in place edit) option, with the same
> often-undesirable hard link
> breakage.
> --
> Cameron Simpson <cs@zip.com.au>

Thanks, Cameron. My knowledge of sed got stuck at the O'Reilly book "sed and awk" and didn't realize the GNU version had many more options. I found my book on the shelf. It was published in 1997.

Yong Huang




--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
 
Old 10-26-2008, 02:16 AM
Cameron Simpson
 
Default replace string

On 25Oct2008 18:05, Yong Huang <yong321@yahoo.com> wrote:
| > | > From: "Mad Unix" <madunix@gmail.com>
| > | > find /dir -name "*.html" -exec sed i 's/"old"/"new"/g' {} ;
| > | Even if you get your sed command right, that won't do in-place
| > | replacement, because if you use sed, the result has to be saved to a
| > | different file and you mv that file to overwrite your original file.
| >
| > He is trying to use GNU sed's -i option, [...]
| Thanks, Cameron. My knowledge of sed got stuck at the O'Reilly book
| "sed and awk" and didn't realize the GNU version had many more options. I
| found my book on the shelf. It was published in 1997.

I try to stick to the same usage as you (and, indeed, the same book!)

I just happen to know the GNU sed has some extra stuff because I see
people using it. Personally, I avoid it (extra non-portable features)
unless I really gain a large benefit from it; as soon as you use such
things you are stuck when you go to another system which doesn't use the
GNU tools, and also you start to forget the portable way and write more
and more stuff that doesn't port.

Cheers,
--
Cameron Simpson <cs@zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

(about SSSCA) I don't say this lightly. However, I really think that the U.S.
no longer is classifiable as a democracy, but rather as a plutocracy.
- H. Peter Anvin <hpa@hera.kernel.org>

--
redhat-list mailing list
unsubscribe mailto:redhat-list-request@redhat.com?subject=unsubscribe
https://www.redhat.com/mailman/listinfo/redhat-list
 

Thread Tools




All times are GMT. The time now is 01:04 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org