Computing.Net > Forums > Unix > Modifying contents of file with sed

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Modifying contents of file with sed

Reply to Message Icon

Name: natnit
Date: April 19, 2006 at 12:23:54 Pacific
OS: Win XP
CPU/Ram: Athol 1 gig
Product: homebuilt
Comment:

Hey again. Just wanted to thank the forum for being so helpful last time I was here. :) Helped save me from a lot of headaches, hehe.

I have a file that has a line somewhere in it that reads:

int SEED = 12345;

How would I use sed to find that instance in the file, and change the file that once, so something like

./CHANGE_SEED 21
would change that line in the file to
int SEED = 21;
and ./CHANGE_SEED 12345
would change it back.

Thanks in advance for all the help. :)

--Natnit




Sponsored Link
Ads by Google

Response Number 1
Name: lchi2000g
Date: April 19, 2006 at 17:44:44 Pacific
Reply:

Your file name with:
int SEED = ...;
is input.txt

In CHANGE_SEED file:

#!/bin/ksh
sed "s/int SEED = [0-9]*;/int SEED = $1;/" input.txt

Run it:
$ ./CHANGE_SEED 12345

Luke Chi


0
Reply to Message Icon

Related Posts

See More


Numerical sort with sort std error line count



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Modifying contents of file with sed

Insert contents of file into variab www.computing.net/answers/unix/insert-contents-of-file-into-variab/7675.html

Moveing content of files into file www.computing.net/answers/unix/moveing-content-of-files-into-file/7688.html

Count # of files with a string www.computing.net/answers/unix/count-of-files-with-a-string/7511.html