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

Modifying contents of file with sed

Reply to Message Icon

Original Message
Name: natnit
Date: April 19, 2006 at 12:23:54 Pacific
Subject: Modifying contents of file with sed
OS: Win XP
CPU/Ram: Athol 1 gig
Model/Manufacturer: 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



Report Offensive Message For Removal

Response Number 1
Name: lchi2000g
Date: April 19, 2006 at 17:44:44 Pacific
Subject: Modifying contents of file with sed
Reply: (edit)

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


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Modifying contents of file with sed

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software