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 and replace and keep Celvin VK Shell Programming and Scripting 3 04-03-2009 01:34 PM
awk find/replace RobertSubnet Shell Programming and Scripting 2 03-08-2009 01:45 PM
find and replace using sed arvind_aks15 Shell Programming and Scripting 2 07-18-2008 05:26 PM
Help in find and replace. nua7 UNIX for Advanced & Expert Users 22 06-26-2008 06:07 AM
find and replace rakshit Shell Programming and Scripting 4 01-24-2008 03:52 AM

Reply
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 06-17-2009
sakthifire sakthifire is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 26
find,replace and default

Hi
Can you please help on this ?

sach.txt:
--------

temp_tab_a.column01=temp_tab_b.column21
temp_tab_c.column01=temp_tab_b.column22
temp_tab_d.column01=temp_tab_c.column32

temp_tab_*.......... goes further

I want to replace temp_tab_a with A, temp_tab_b with B and other alias(temp_tab_*) with X (default value) . The file we are going to replace has multiple lines like the above. It should look like the below.

A.column01=B.column21
X.column01=B.column22
X.column01=X.column32


The file we are going to replace has multiple lines like the above. We want a script that handles multiple lines like the above.


Thanks
Sakthifire
  #2 (permalink)  
Old 06-17-2009
vguleria vguleria is offline
Registered User
  
 

Join Date: Mar 2008
Location: India(Sarkaghat)
Posts: 28
sed -e s/temp_tab_a/A/g -e s/temp_tab_b/B/g -e s/temp_tab_[c-z]/X/g sach.txt


Regards,
VG
  #3 (permalink)  
Old 06-17-2009
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474
a bit change to vguleria's solution

Code:
sed -e 's/temp_tab_a/A/g' -e 's/temp_tab_b/B/g' -e 's/temp_tab_[^ab]/X/g'
  #4 (permalink)  
Old 06-18-2009
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,082
i think below perl may a little bit faster, since only go through the whole file once.

Code:
while(<DATA>){
	s/temp_tab_([^.]*)/($1 eq 'a')?'A':($1 eq 'b')?'B':'X'/eg;
	print;
}
__DATA__
temp_tab_a.column01=temp_tab_b.column21
temp_tab_c.column01=temp_tab_b.column22
temp_tab_d.column01=temp_tab_c.column32
Reply

Bookmarks

Tags
awk, find, sed

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 06:47 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