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
Find/replace to new file: ksh -> perl McLan Shell Programming and Scripting 1 05-16-2008 12:14 AM
Problem with pattren Matching pbsrinivas Shell Programming and Scripting 7 11-27-2006 12:17 AM
Search for a Pattren in the files. sbasetty Shell Programming and Scripting 2 10-05-2006 09:43 AM
find and replace a pattern in a file krishnamaraju Shell Programming and Scripting 1 08-29-2006 07:02 AM
Find replace within a file? yankee428 UNIX for Dummies Questions & Answers 2 06-15-2005 09:32 AM

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

Join Date: May 2007
Posts: 2
find and replace pattren in file

Hi,

I have the input file having data as follow:
file1.txt
001 aaa_1:abcd
002 bbb_2:abcd

I want output as,
001xabcd
002xabcd

Here iam trying to replace "{1 space}{alphanumeric string with underscore}{:}" with characrter "x".
I tried to achieve this using sed;but Iam not getting this correctly.

Thanks in advance.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-08-2007
Playing with Ubuntu Now!
 

Join Date: Oct 2005
Location: Chennai
Posts: 364
check this

Code:
sed 's/^\(.*\) \(.*:\)\(.*\)$/\1x\3/g' testfile
Reply With Quote
  #3 (permalink)  
Old 08-08-2007
Registered User
 

Join Date: May 2007
Posts: 211
Code:
sed 's/ .*:/x/' file1.txt
Reply With Quote
  #4 (permalink)  
Old 08-08-2007
Registered User
 

Join Date: Feb 2006
Location: Southern England
Posts: 102
perl -i.bak -pe 's/THIS/THAT/g' file ...
Reply With Quote
  #5 (permalink)  
Old 08-09-2007
Registered User
 

Join Date: May 2007
Posts: 2
It's working!!!

Thanks.
Reply With Quote
  #6 (permalink)  
Old 08-09-2007
robotronic's Avatar
Can I play with madness?
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Agreeing with your request, the {alphanumeric string with underscore} corresponds to "[0-9a-zA-Z_][0-9a-zA-Z_]*". So:

Code:
sed "s/ [0-9a-zA-Z_][0-9a-zA-Z_]*:/x/g" file1.txt
But I think this is better:

Code:
sed "s/ .*:/x/g" file1.txt
Bye
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 08:31 PM.


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