Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 03-11-2004, 07:13 AM   #1
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,
Old 03-11-2004, 07:25 AM   #2
Registered: Feb 2004
Posts: 140

Rep: Reputation: 15
Here are some examples:

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

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

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


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

Rep: Reputation: 110Reputation: 110
"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....
Old 03-11-2004, 08:42 PM   #4
LQ Newbie
Registered: Jan 2004
Posts: 25

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


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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:02 AM.

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