Print columns matching to specific values

Hello Friends,

I have a CDR file and i need to print out 2 columns with their field position which matches to some constant values,

a part of input file

CZ=1|CZA=1|DIAL=415483420001|EE=13|ESF=1|ET=[16/04/2012][10:44:46:435]|FF=0|9|MNC=99|MNP=9041|MTC=0|NID=2|NOA=international|ON=1|
OutPut

3,DIAL=415483420001|13,NOA=international

i need to print out the colums which matches constant "DIAL" and "NOA" values, but the field of these values changing from records to records so i cant print a constant columns like $3 and $13...

I tried something but failed, working first time on AIX,

i know the answer somewhere in the database somehow i couldnt find it.. appreciate any help,

BR

perl -F'\|' -ane 'for($i=0;$i<@F;$i++){($F[$i] =~ /DIAL|NOA/) && print $i+1,",$F[$i]|"}; print "\n"' inputfile
1 Like
$ awk -F\| '{for(i=1;i<=NF;i++)if($i~/DIAL|NOA/)printf(" %s %s|",i,$i)}{print ""}' input.txt
 3 DIAL=415483420001| 13 NOA=international|

if you dont want the | as the last character then pipe the output to sed command

sed 's/|$//'
1 Like

Different than my first question ifi need to change FF=0 Fields as FF=1 how could i manipulate the code?

awk -F\| '{for(i=1;i<=NF;i++)if($i~/^FF/)print($i="1")}{print ""}' input.txt

prints only "1" the value of FF column :frowning: