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
Deleting lines inside a file without opening the file toms Shell Programming and Scripting 3 09-24-2007 04:58 AM
making change in file without opening it naamas03 Shell Programming and Scripting 0 04-04-2006 01:11 AM
Opening a file during FTP ceaker High Level Programming 1 03-31-2006 11:40 PM
delete file without opening vi lweegp UNIX for Dummies Questions & Answers 7 01-25-2006 10:23 AM
opening a file hiei UNIX for Dummies Questions & Answers 4 03-31-2004 09:24 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-13-2006
Registered User
 

Join Date: Oct 2001
Posts: 6
Stumble this Post!
Making Changes without opening file

Hello,

I'm new to scripting, I have a file test.dat. I want to make changes to it with out openning it.

Example: test.dat has rows, and I want to change value "LA" to "TX" without opening it or without writing it to another file.

Is it possible?

Thanks
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-13-2006
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Stumble this Post!
perl -pi -e "s/LA/TX/g;" test.dat

Cheers
ZB
Reply With Quote
  #3 (permalink)  
Old 03-13-2006
Registered User
 

Join Date: Mar 2006
Posts: 1
Stumble this Post!
Try this one sed 's/LA/TX/g' filename > filename1
Reply With Quote
  #4 (permalink)  
Old 03-13-2006
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,547
Stumble this Post!
Quote:
Originally Posted by dhana_1979
Try this one sed 's/LA/TX/g' filename > filename1
request was not to write to another file,
your command redirects to filename1
in such a case you need to use the -i option available in GNU sed
Reply With Quote
  #5 (permalink)  
Old 03-14-2006
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,002
Stumble this Post!
Code:
(echo 'g/LA/TX/g'; echo 'wq') | ex -s filename
Reply With Quote
  #6 (permalink)  
Old 03-14-2006
Registered User
 

Join Date: Jul 2005
Posts: 137
Stumble this Post!
Code:
ruby -i -pe 'gsub(/LA/,"TX")' test.dat
Reply With Quote
  #7 (permalink)  
Old 03-15-2006
Registered User
 

Join Date: Feb 2006
Location: JP.Tokyo
Posts: 30
Stumble this Post!
Quote:
awk '{gsub("LA","TX"); print}' filename
I asked the same question last time ^O^. Its the easiest way to solve ur problem.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 01:10 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