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
problem while making ftp of a large file rprajendran UNIX for Dummies Questions & Answers 1 05-27-2008 10:19 PM
making an iso file... asafronit SCO 5 03-08-2008 02:18 PM
Permanent file deletion - sensitive data peteroc UNIX for Advanced & Expert Users 5 06-20-2007 09:10 AM
Making Changes without opening file irehman Shell Programming and Scripting 9 03-16-2006 06:13 AM
sed : Making changes in the same file amol Shell Programming and Scripting 3 07-17-2002 03:50 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-22-2007
Registered User
 

Join Date: Feb 2006
Posts: 22
Arrow making the changes permanent in a file

Hi Friends.
I have a file called install.data which has fields like :

XXXXX
ACVCGFFTFY UAHIUH OI
CONNECTION=tape/11/
LOCATAION=08-90-89
SIZE=90

I had to change the values of some of these variables. So i did :
grep "SIZE" instal.data | sed 's/[0-9]*/00/' ...this is working fine on command line but i want to make this change permanent in the file without redirecting it to
other file .I dont want to make the changes in the Vi editor . I need to use some command . Can you help in this ???

Thanks,
Vijayaa
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 05-22-2007
Registered User
 

Join Date: Nov 2006
Posts: 39
My suggestion would be to have your sed command in a script and have it output to a temp file and then have the mv command write the temp file over the original file.
Reply With Quote
  #3 (permalink)  
Old 05-22-2007
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,211
If perl is available on your system, you can do something like that :
Code:
perl -p -i -e '/SIZE/ and s/[0-0]*/00/'  instal.data
Jean-Pierre.
Reply With Quote
  #4 (permalink)  
Old 05-22-2007
Registered User
 

Join Date: Mar 2007
Location: Chennai
Posts: 222
Hi,
This is a sample script incase you need to run on single or multiple files in a directory.

Code:
#!/bin/ksh
for file in *.txt ; do  
  sed  's/SIZE=[0-9][0-9]*/SIZE=00/g' $file > /tmp/${file}.new;   
  mv ${file} ${file}.old #Taking a backup before overwriting
  mv /tmp/${file}.new $file;
done
Thanks
Nagarajan Ganesan.
Reply With Quote
  #5 (permalink)  
Old 05-22-2007
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,593
if thats GNU sed, use the -i option
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:17 PM.


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

Content Relevant URLs by vBSEO 3.2.0