From this data:STRING1,c45621396a774a7a79b095a1b73b1d3b,2016-04-14T19:39:41.529978,1.0.4.4,7-sp1.0-amd64,,10.224.241.219|0.0.0.0|0.0.0.0|192.168.0.6|0.0.0.0STRING2,c5815139f3051de2ab67909b03a01203,2016-04-14T19:37:47.991569,1.0.4.4,7-sp1.0-amd64,,10.230.16.188STRING3,c837513923e2abfe4df41c2240d1c869,2016-04-14T19:40:10.385759,1.0.4.4,7-sp1.0-amd64,,0.0.0.0|0.0.0.0|0.0.0.0|10.226.41.43STRING4,c837544923e2abfe4df41c2240d1c869,2016-04-14T19:40:10.385779,1.0.4.4,7-sp0.0-amd64,,8.8.8.8|0.0.0.0|0.0.0.0|0.0.0.0|10.226.41.43STRING5,c837544003e2abfe4df41c2240d1c869,2016-04-14T19:40:10.382379,1.0.4.4,7-sp0.0-amd64,,0.0.0.0|10.20.40.6|0.0.0.0|10.226.41.43I wish to keep onlythe first field (which is a string with unpredictable alphanum/length) andfrom the sixth field, only IP addresses (there may be one or more) beginning with 10.Based on the sample below, here's the desired output:STRING1 10.224.241.219STRING2 10.230.16.188STRING3 10.226.41.43STRING4 10.226.41.43STRING5 10.20.40.6 10.226.41.43What's the sed/awk magic that can achieve this? I can use any standard text processing utils on a GNU/Linux system or cygwin to achieve this.Thanks
Print multiple fields based on partial substring match inside one of the fields
text processing
If your fields never contain commas, you could try:$ perl -F, -lane '@k=split(/[|]/,$F[6]);                   @l=grep{/^10\./}@k;                   print $F[0] @l' file |     sed 's///g'STRING1 10.224.241.219STRING2 10.230.16.188STRING3 10.226.41.43STRING4 10.226.41.43STRING5 10.20.40.6 10.226.41.43ExplanationPerl's -a option makes it work like awk, it will split its input files on the value given by -F and save each resulting field as an element in the array @F. So, the 1st field will be $F[0], the 2nd $F[1] etc. The -l option adds a newline to each print call and the -n tells perl to read its input file line by line and apply the script given by -e to each line.@k=split(/[|]/,$F[6]); : split the 7th field on  or | and save it as the array @k. This will be the IPs. @l=grep{/^10\./}@k; : save all fields from @k that start with a 10 in the array @l. print $F[0] @l : print the 1st field and whatever is in @l. sed 's///g' : remove quotes. Since perl will split the input lines before running anything else, it is easier to use another program for this. You could also shorten the Perl script by not using temporary array variables:perl -F, -lane 'print $F[0] , join  , grep{/^10\..*/} split(/[|]/,$F[6])' file