Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 04-26-2003, 11:01 AM   #16
Registered: Dec 2002
Posts: 226

Rep: Reputation: 30

ok m0rl0ck,

s1 contains

show us how, with sed, you would change s1 so that all aaX -> aaY
Old 04-28-2003, 08:27 AM   #17
Senior Member
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,304

Rep: Reputation: 65
cat s1| sed s/aaX/aaY/g > s2 && cp -f s2 s1

i think
Old 04-28-2003, 08:49 AM   #18
LQ Guru
Registered: Nov 2002
Location: Durham, England
Distribution: Fedora Core 4
Posts: 1,565

Rep: Reputation: 57
Sed works fine for search and replace. You have to keep two things in mind however,

1) sed doesn't do all regexps that Perl does. That's not normally a problem.

2) Pipe asyncronity.

That last one means don't try and alter a file like this:

cat file | sed 's/one/two/' > file

which will just corrupt stuff. Do one of these:

cat file | sed 's/one/two/' >file2; mv file2 file


( exec 6<file; rm file; sed <&6 's/one/two' >file )
Old 04-28-2003, 09:01 AM   #19
Registered: Dec 2002
Posts: 226

Rep: Reputation: 30
which again leads to the conclusion (as was said previously):

sed is "stream editor", not file editor. If you want to directly modify a file, you need perl or ex.

perl and ex can do the job in 1 command, sed requires at least 2 commands


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
global search and replace? jkcunningham Linux - General 5 03-15-2006 02:43 PM
search and replace in every file Thinking Programming 3 07-30-2005 05:50 PM
How to search and replace a text using grep DediPlace Linux - General 2 05-29-2005 06:47 PM
find with grep and replace it dominant Linux - Newbie 4 03-03-2004 01:11 PM
problem in perl replace command with slash (/) in search/replace string ramesh_ps1 Red Hat 4 09-10-2003 01:04 AM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:42 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration