LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
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 01-07-2009, 02:58 PM   #1
faizlo
Member
 
Registered: Sep 2008
Location: USA
Distribution: Linux Mint Qiana
Posts: 190

Rep: Reputation: Disabled
Help with sed


Hi All,

I am beginning my way into sed, I want to do the following:

I have a file "file" which contains few lines. I have two different words in two different lines (word1 in line 1 and word2 in line 4) which I need to change to be "change1" in line 1, and "change2" in line4. They should be replaced in the same file, i.e. keep the file name intact "file".
How would I do that?

Here is exactly what I want:
Code:
void FV(string infile = "test2.xxx",
            bool ele = 0,
            bool exit=1,
            string leafname = "output2",
            int nbins = 75,
            float xmin  = 0,
            float xmax  = 1.0000001 ){
I want "test2.xxx" to be test3.xxx, and "output2" to be "output3"

Thank you so much in advance,

faizlo

Last edited by faizlo; 01-07-2009 at 03:01 PM.
 
Old 01-07-2009, 04:45 PM   #2
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
I have called your file tsed - this will make the changes in place. Note the changes will not be confined to lines 1 and 4 but as I take it the searched expressions are unique this will be OK :
Code:
 
sed -i -e "s/test2.xxx/test3.xxx/" -e "s/output2/output3/"  tsed
 
Old 01-07-2009, 06:49 PM   #3
faizlo
Member
 
Registered: Sep 2008
Location: USA
Distribution: Linux Mint Qiana
Posts: 190

Original Poster
Rep: Reputation: Disabled
It worked, Thank you so much,

faizlo
 
Old 01-07-2009, 07:26 PM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,121

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Yes, but do you understand why it worked ?.
 
Old 01-07-2009, 08:05 PM   #5
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 232Reputation: 232Reputation: 232
Quote:
Yes, but do you understand why it worked ?.
Good point.

I would hope that those asking for help would maybe have hit a "brick wall" in their trials and so need assistance or guidance.

Our solutions are all offered freely in the spirit of helpfulness and to further knowledge but lets hope the enquirers are not just taking advantage of this for an easy ride.
 
Old 01-07-2009, 10:40 PM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by syg00 View Post
Yes, but do you understand why it worked ?.
You took the words right out of my mouth. It is so tempting to approach these questions as a teacher---showing the student how to find the answer, but not giving them the answer.
 
Old 01-07-2009, 11:11 PM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,121

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
I note the OP has now taken this answer and started a new thread with it. Appears prepared to learn.
 
  


Reply



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
help with sed... Ateo Programming 5 09-03-2006 03:57 PM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
[sed] "Advanced" sed question(s) G00fy Programming 2 03-20-2006 12:34 AM
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-03-2005 11:00 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:59 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
Open Source Consulting | Domain Registration