The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how to delete content in a file (delete content only) kittusri9 Shell Programming and Scripting 5 05-15-2008 10:12 AM
Content of Content of a variable! jaduks Shell Programming and Scripting 2 08-26-2007 09:40 PM
Using the content of a file in the name of another anriot Shell Programming and Scripting 2 09-18-2006 04:56 PM
Mass Change content in all files terala Shell Programming and Scripting 1 11-19-2005 09:30 PM
Content-Type primal UNIX for Dummies Questions & Answers 1 12-20-2001 08:36 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-19-2007
manas_ranjan's Avatar
Registered User
 

Join Date: Jul 2007
Location: PUNE
Posts: 157
Stumble this Post!
how to change the content thru sed.....

Hi Everybody,

Another headache form myside,

i have a file name noname.txt having content as
CS007=NEW

and i have to write a scipt which will take the parameters as update,delete... with the 1st field of noname.txt (i.e. here CS007)
whose objective is to change the 2nd field of noname.txt as update or delete as per the input.

how can i achieve this for the following line.......
sed ' /CS007/ c\CS007=UPDATE' noname.txt using the variables...

like

sed ' /$1/ c\$1=$2' noname.txt

any other suggestions are also welcome....

Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-19-2007
Registered User
 

Join Date: Jul 2006
Posts: 139
Stumble this Post!
sed " /$1/ c\$1=$2" noname.txt

should do...
Reply With Quote
  #3 (permalink)  
Old 09-19-2007
Yogesh Sawant's Avatar
Part Time Moderator and Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 767
Stumble this Post!
An alternative in Perl:
Code:
perl -pi -e "s/(CS007=)NEW/\1UPDATE/" noname.txt
but probably this doesn't fit your requirement
Reply With Quote
  #4 (permalink)  
Old 09-22-2007
manas_ranjan's Avatar
Registered User
 

Join Date: Jul 2007
Location: PUNE
Posts: 157
Stumble this Post!
Thanx a lot....

the following method is also working,

'/'"$1"'/ c\'"$1"="$2"
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
perl, sed

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:43 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0