The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
replace nth instance of string uttamhoode Shell Programming and Scripting 4 04-03-2008 02:25 AM
sed replace 2nd instance katrvu Shell Programming and Scripting 2 02-12-2008 02:17 PM
OTRS instance naik_mit Linux 7 05-23-2005 06:42 AM
Copy Db Instance cobdeng UNIX for Dummies Questions & Answers 0 01-12-2005 07:48 AM
finding first instance peter.herlihy UNIX for Dummies Questions & Answers 20 08-14-2002 03:52 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-07-2008
IronHorse7 IronHorse7 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 2
replace first instance(not first instance in line)

Alright, I think I know what I am doing with sed(which probably means I don't). But I cant figure out how to replace just the first occurance of a string. I have tried sed, ed, and grep but can't seem to figure it out. If you have any suggestions I am open to anything!
  #2 (permalink)  
Old 02-07-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,861
By "first occurance" do you mean first occurance in a line or first occurance in a file?
  #3 (permalink)  
Old 02-07-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,861
Assuming it is the first occurance in a file, the following example should show you how to
do what you want to do using awk.

Code:
$ cat file
true line1
true line2
$ awk '/true/ && n == 0 { sub(/true/,"false"); ++n } { print }' file
false line1
true line2
$
  #4 (permalink)  
Old 02-07-2008
IronHorse7 IronHorse7 is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 2
Thank you

You are awsome, THANKS!
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 10:11 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0