I'm trying to do the following with just one awk command. I have a text file with the following structure
First fields are separated with ":", last field (host list) separated by spaces
Uniq id:Name:Uniq identifier:host_list (may be empty to many and can be repeated)
sv_0:blabla:205700DD4C506261796ED3:Host_10 Host_1 Host_16
sv_111:abcd:205700DD4C50629585735C:Host_10
sv_3:xpto1:2057008E714F629B3BCDCF:Host_11 Host_10
sv_46:something:205700DD4C50629E5AB93A:
sv_0 blabla 205700DD4C506261796ED3 Host_10
sv_0 blabla 205700DD4C506261796ED3 Host_1
sv_0 blabla 205700DD4C506261796ED3 Host_16
sv_111 abcd 205700DD4C50629585735C Host_10
sv_3 xpto1 2057008E714F629B3BCDCF Host_11
sv_3 xpto1 2057008E714F629B3BCDCF Host_10
sv_46 something 205700DD4C50629E5AB93A
Using the next command works, but I don't like to use pipe after pipe
awk -F: '{print $1" "$2" "$3" "$4 }' file.txt | awk '{nfield=4; while (NF >= nfield) {print $1" "$2" "$3" "$nfield; nfield++}}'
With single gawk command:
awk -F'[: ]' '{ for (i=4;i<=NF;i++) print $1,$2,$3,$i }' file.txt
sv_0 blabla 205700DD4C506261796ED3 Host_10
sv_0 blabla 205700DD4C506261796ED3 Host_1
sv_0 blabla 205700DD4C506261796ED3 Host_16
sv_111 abcd 205700DD4C50629585735C Host_10
sv_3 xpto1 2057008E714F629B3BCDCF Host_11
sv_3 xpto1 2057008E714F629B3BCDCF Host_10
sv_46 something 205700DD4C50629E5AB93A
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With