![]() |
|
|
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 |
| String substitution | ctrl-alt-del | Shell Programming and Scripting | 3 | 10-14-2008 03:37 AM |
| string substitution | laxmi | Shell Programming and Scripting | 3 | 02-16-2008 06:11 AM |
| String Substitution | laxmi | UNIX for Advanced & Expert Users | 1 | 02-16-2008 06:08 AM |
| Sed - substitution for whole string | Scarlos | Shell Programming and Scripting | 4 | 07-12-2005 08:56 AM |
| Sed String Substitution | pciatto | UNIX for Dummies Questions & Answers | 2 | 04-29-2002 11:10 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
substitution of string in brackets
Hi friends!
I have a tab delimited file with two columns : GB_45_DRB SP:0139466(mrmi sisignm)|SP:3674(fllflg_itoioh)|SP:68954779(RMTKLGF to emmdm-roomto) GB_45_DRD SP:475928(mgmdksi rikgkg)|SP:587959(roykgl tiic-tm)|SP:0139466(mrmi sisignm)|SP:3674(fllflg_itoioh)|SP:68954779(RMTKLGF to emmdm-roomto) GB_45_DRCD GB_45_P5294 SP:3735599(fkkfdlk) I want to remove all occurences of stuff between brackets(inclusive of brackets) in second column and replace all "|" with ";" So that it looks like SP:0139466;SP:3674;SP:68954779 in second col. Problem is that second col might be empty, as in third row here. Ur help would be appraciated.. Thanks Last edited by jacks; 12-05-2008 at 01:25 PM.. |
|
||||
|
Try this one: Code:
awk -F"[()]" '{
gsub(/\|/, ";", $0);
n=split($0, arr, /[()]/);}
{for (i=1; i<=n; i++)
if(i%2 == 1)
printf ("%s", $i)
}
{print "";}
' yourfilename
The output I got is: Code:
GB_45_DRB SP:0139466;SP:3674;SP:68954779 GB_45_DRD SP:475928;SP:587959;SP:0139466;SP:3674;SP:68954779 GB_45_DRCD GB_45_P5294 SP:3735599 |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|