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
how do i pattern match a field with awk? someone123 Shell Programming and Scripting 4 06-03-2008 09:08 AM
To identify filename in which having match PATTERN cedrichiu Shell Programming and Scripting 14 03-23-2008 08:05 PM
how can awk match multi pattern in a string sleepy_11 UNIX for Advanced & Expert Users 5 03-16-2008 11:40 PM
how to use pattern match with grep rei UNIX for Dummies Questions & Answers 5 01-05-2007 04:33 AM
vi/vim : complex pattern substitution c444l UNIX for Dummies Questions & Answers 2 08-03-2004 11:04 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-20-2006
frustrated1 frustrated1 is offline
Registered User
  
 

Join Date: Aug 2003
Location: Ireland
Posts: 278
pattern match and substitution, can you help?

pattern match and substitution, can you help?

file named test.txt
I want to replace all the words Event with the word Fatal in all lines containing the word ERR - but I also want to keep the output of the other lines not matching ERR


Test.txt:
Event 13 INF egegegege
Event 14 INF egegegege
Event 15 ERR egegegege
Event 16 MSG egegegege

The output I want it:
Event 13 INF egegegege
Event 14 INF egegegege
Fatal 15 ERR egegegege
Event 16 MSG egegegege
  #2 (permalink)  
Old 02-20-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Code:
sed -e '/ERR/{s_Event\(.*\)_Fatal\1_g}' input.txt > output.txt
  #3 (permalink)  
Old 02-20-2006
frustrated1 frustrated1 is offline
Registered User
  
 

Join Date: Aug 2003
Location: Ireland
Posts: 278
Doesnt appear to work - any ideas?

bash-2.05# cat test.txt
Event 13 INF egegegege
Event 14 INF egegegege
Event 15 ERR egegegege
Event 16 MSG egegegege

bash-2.05# sed -e '/ERR/{s_Event\(.*\)_Fatal\1_g}' test.txt
sed: command garbled: /ERR/{s_Event\(.*\)_Fatal\1_g}
  #4 (permalink)  
Old 02-20-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,798
Code:
sed -e '/ERR/s/Event/Fatal/g' test.txt
  #5 (permalink)  
Old 02-20-2006
frustrated1 frustrated1 is offline
Registered User
  
 

Join Date: Aug 2003
Location: Ireland
Posts: 278
Aha - I knew there must be a relatively simple way.. I am using sed but not well up on this and was not sure of the syntax..

Thanks for all your help!!
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 07:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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