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

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 08-09-2007
gopalss gopalss is offline
Registered User
  
 

Join Date: May 2007
Posts: 3
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.
  #2 (permalink)  
Old 08-09-2007
ranj@chn ranj@chn is offline Forum Advisor  
Playing with Ubuntu Now!
  
 

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

Code:
sed 's/^\(.*\) \(.*:\)\(.*\)$/\1x\3/g' testfile
  #3 (permalink)  
Old 08-09-2007
lorcan lorcan is offline
Registered User
  
 

Join Date: May 2007
Posts: 219
Code:
sed 's/ .*:/x/' file1.txt
  #4 (permalink)  
Old 08-09-2007
bigearsbilly bigearsbilly is offline
Registered User
  
 

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

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

Thanks.
  #6 (permalink)  
Old 08-09-2007
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
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
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:39 PM.


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