LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-11-2004, 07:13 AM   #1
chuanyung
LQ Newbie
 
Registered: Jan 2004
Posts: 25

Rep: Reputation: 15
[sed] replace string?


Dear all,

I'm sorry that I can't understand when I man sed.
What I want to do are replacing some string and inserting strings in first line.

The strings I want to replace, ex:
first second; ==> //first second;
#include <FlexLexer.h> ==> #include "FlexLexer.h"

I may insert a string,such as #include "myheader.h", to first line of some file.

How should I do?
Thanks for your help.

Best Regards,
chuanyung.
 
Old 03-11-2004, 07:25 AM   #2
mhiggins
Member
 
Registered: Feb 2004
Posts: 140

Rep: Reputation: 15
Here are some examples:

One file
sed s/\<FlexLexer.h\>/\"FlexLexer.h\"/ yourfile.c >yourfile.new; mv yourfile.new yourfile.c

a few files
for i in 'file1 file2 file3'
do
sed s/\<FlexLexer.h\>/\"FlexLexer.h\"/ $i >$i.new
mv $i.new $i
done

A dir tree of files
for i in `find -name file\*`
do
sed s/\<FlexLexer.h\>/\"FlexLexer.h\"/ $i >$i.new
mv $i.new $i
done

-Matt

Not tested but should work ...
 
Old 03-11-2004, 10:31 AM   #3
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
"info sed" is much explainig than "man sed".
If you're not familiar with "info" try readingi "info info"

Here's more sed explanation, examples, tricks....
http://www.faqs.org/faqs/editor-faq/sed/
http://main.rtfiber.com.tw/~changyj/sed/
http://sed.sourceforge.net/grabbag/
 
Old 03-11-2004, 08:42 PM   #4
chuanyung
LQ Newbie
 
Registered: Jan 2004
Posts: 25

Original Poster
Rep: Reputation: 15
Thanks, I finished it.
 
  


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
Problem using sed to replace string in file umk Debian 12 02-01-2012 08:39 AM
How can I replace this string with another using sed? dave4545 Programming 7 01-27-2006 10:58 AM
Replace substring with SED marri Programming 2 07-09-2005 05:18 PM
problem in perl replace command with slash (/) in search/replace string ramesh_ps1 Red Hat 4 09-10-2003 01:04 AM
Sed - suitable to replace CR LF? J_Szucs Programming 3 05-12-2003 06:03 PM


All times are GMT -5. The time now is 01:16 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration