![]() |
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 |
| replacing a nul field with text | DarkHound | Shell Programming and Scripting | 3 | 09-04-2007 02:34 PM |
| Moving Part of a field to another field using AWK | rjsha1 | Shell Programming and Scripting | 5 | 08-04-2006 05:39 AM |
| Replacing certain field | charbel | Shell Programming and Scripting | 1 | 04-26-2006 04:00 PM |
| add increment field when first field changes | azekry | Shell Programming and Scripting | 2 | 11-14-2005 04:21 PM |
| Replacing the last field of a line. | Darek | Shell Programming and Scripting | 3 | 08-19-2005 11:45 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
need help with replacing a certain field...
Hi, can anyone help me? This is what i want to do....I have a string
UNB+UNOA:1+OOCLIES+RTTC+080408:0358+1' and i want to replace the "1" at the end (that specific field only) to 00001 such that the new output will be like this UNB+UNOA:1+OOCLIES+RTTC+080408:0358+00001' i tried using sed but it replaces all the "1"'s it encounters..i only need the "1" in the last part....maybe it has something to do with cut -d+ -f6? I'm not entirely sure... I already figured out how to pad 1 with zeros to make it's width 5 but am having trouble with the replacement part. Please help anyone...and thank you very much in advance!!! |
|
||||
|
Quote:
Code:
echo 'UNB+UNOA:1+OOCLIES+RTTC+080408:0358+1' | sed 's/[0-9]$/0000&/' |
|
||||
|
Hi all, thank you very much for your replies...but can you please explain what happened? Because i can see that you coded it as only "1", but see, these can be any number from 1-99999. what happens is i need to pad the said number with zeros to make it have a width of 5.
My code is as follows: currCtlNo=`echo "UNB+UNOA:1+OOCLIES+RTTC+080408:0358+1" | cut -d+ -f6 | cut -d"'" -f1` newCtlNo=$currCtlNo typeset -Z5 newCtlNo then i want to replace the last portion with the $newCtlNo..only the last portion |
|
||||
|
i already got it =)
UNB_seg="UNB+UNOA:1+OOCLIES+RTTC+080408:0358+1'" currCtlNo=`echo $UNB_seg | cut -d+ -f6 | cut -d"'" -f1` newCtlNo=$currCtlNo typeset -Z5 newCtlNo echo $UNB_seg | awk -F"+" '{$NF="'$newCtlNo'"}1' OFS="+" > newfile.txt cat newfile.txt the result is: UNB+UNOA:1+OOCLIES+RTTC+080408:0358+00001' but can you please explain the awk statement? I would just like to better understand what happened. ![]() Thank you in advance! and thank you everyone! ![]() |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|