LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 04-26-2003, 12:01 PM   #16
arnold
Member
 
Registered: Dec 2002
Posts: 226

Rep: Reputation: 30

ok m0rl0ck,

s1 contains
aaXaaXaaXaaXaaXaaXaaXaaXaaXaaX
aaXaaXaaXaaXaaXaaXaaXaaXaaXaaX

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

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

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

Rep: Reputation: 47
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

or

( exec 6<file; rm file; sed <&6 's/one/two' >file )
 
Old 04-28-2003, 10:01 AM   #19
arnold
Member
 
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
 
  


Reply


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 03:43 PM
search and replace in every file Thinking Programming 3 07-30-2005 06:50 PM
How to search and replace a text using grep DediPlace Linux - General 2 05-29-2005 07:47 PM
find with grep and replace it dominant Linux - Newbie 4 03-03-2004 02:11 PM
problem in perl replace command with slash (/) in search/replace string ramesh_ps1 Red Hat 4 09-10-2003 02:04 AM


All times are GMT -5. The time now is 10:47 AM.

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