0

I have a file with tab separated fields (6 of them). One of these fields is a string (field 3). I need to extract a substring and write it at the end of each string after a tab (at position 11). How do I do that? Separator is a symbol /, there are always 3 of them, and I need to extract what is after the second one and before the third one (ex. http://www.host.com/).

2       65      gf/jyhfkhjf/fg  0.5     657     hs
6745    6       lug/hgf/hgd     87      56      kg

The output I want:

2       65      gf/jyhfkhjf/fg  0.5     657     hs      jyhfkhjf
6745    6       lug/hgf/hgd     87      56      kg      hgf

I tried awk for a part of my work, assuming I only have a single field with a string.

awk -F/ '{print $3}'
0

1 Answer 1

2
$ awk 'BEGIN{FS=OFS="\t"} {split($3,t,"/"); print $0, t[2]}' file
2       65      gf/jyhfkhjf/fg  0.5     657     hs      jyhfkhjf
6745    6       lug/hgf/hgd     87      56      kg      hgf

Not the answer you're looking for? Browse other questions tagged or ask your own question.