![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
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 |
|
||||
|
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
|
![]() |
| Bookmarks |
| Tags |
| awk, find, sed |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|