Hi,
i have a huge file that need to check for a pattern that occur more than once in a line like below:-
#lkk>cd-m>A0DV0>192.134.1.1 blablabladsdjsk
jshdfskfslfs
#lqk>cd-m>A1SV0>192.14.11.1 blalalbnalablab
balablablajakjakjakja
#pldqw>sf-w>PH67FR>168.55.1.1 balablabala
bkablablabablablablabalna
blablablaba
there are 3 ">" in the first line for each record. I need to change the third one to "whitespace" and the output shuld be like this:-
#lkk>cd-m>A0DV0 192.134.1.1 blablabladsdjsk
jshdfskfslfs
#lqk>cd-m>A1SV0 192.14.11.1 blalalbnalablab
balablablajakjakjakja
#pldqw>sf-w>PH67FR 168.55.1.1 balablabala
bkablablabablablablabalna
blablablaba
I don't know how to check for the third ">" and change it accordingly. the code that i am using will change all the ">". I used sed and awk to do that. anyone could help me with awk? thanks
Try :
$ awk --re-interval 'match($0,/>[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/){$0 = substr($0,1,RSTART-1) OFS substr($0,RSTART+1)}1' file
#lkk>cd-m>A0DV0 192.134.1.1 blablabladsdjsk
jshdfskfslfs
#lqk>cd-m>A1SV0 192.14.11.1 blalalbnalablab
balablablajakjakjakja
#pldqw>sf-w>PH67FR 168.55.1.1 balablabala
bkablablabablablablabalna
blablablaba
---------- Post updated at 11:52 PM ---------- Previous update was at 11:38 PM ----------
OR this also might work
$ awk 'ORS=!(NR%3)?FS:">"' RS=">" file
#lkk>cd-m>A0DV0 192.134.1.1 blablabladsdjsk
jshdfskfslfs
#lqk>cd-m>A1SV0 192.14.11.1 blalalbnalablab
balablablajakjakjakja
#pldqw>sf-w>PH67FR 168.55.1.1 balablabala
bkablablabablablablabalna
blablablaba
1 Like
Hi Akshay Hedge,
Tried your codes. The first one give me this error
awk: not an option: --re-interval
but the second one worked perfectly and easier to understand. I will look for "re-interval" information as this is the first time i heard this term. Thanks a lot for your help.
Sorry I forgot to mention, that you should have gnu awk
to use --re-interval
1 Like
Hi in2nix4life,
This works perfectly too. thanks