Artificial intelligent assistant

print field that contain a certain value is it possible to print the field that contain a certain value? Consider below file: foo,boo,123,1234312,ABC foo,boo,ABC,bla,bla There is a field that contain `ABC` but it is not a fixed with all records, so the command need to print `$5` in the first record and `$3` in the second one.

Yes, just like in your previous question, but match each field:


$ awk -F, '{for(i=1;i<=NF;i++){if($i~/ABC/){print $i}}}' file
ABC
ABC


Note that the above will also print a filed that _contains_ `ABC`, like `fooABC` or `fooABCbar` or whatever. To print only fields that _are_ `ABC`, use:


awk -F, '{for(i=1;i<=NF;i++){if($i=="ABC"){print $i}}}' file


The same thing, in Perl:


perl -F, -lane 'print grep{/ABC/}@F' file ## field matches
perl -F, -lane 'print grep{$_=="ABC"}@F' file ## field is

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy ebb79d3680718c716944b9f7c57a9c79