Retrieving a specific value

I have this input file:

I want to get the following output file:
Output

Basically, the program would scan the file and look for every instance where the value is < 14.0 dB. The program would then print the row that contains that value along with the corresponding name with the ">".
Be blessed!

kamaraj@kamaraj-laptop:~/Desktop/Scripts$ awk -F"[:[]" ' { if (substr($0,0,3)=="wow") print $0; else if ($2<14) print $0}' filename
wow1>
NLD_2_1: 12.3
wow4>
NLD_1_1: 9.2[dB]
wow15>
NLD_2_1: 8.6[dB]
wow6>
NLD_0_1: 13.9[dB]
NLD_1_1: 13.0[dB]
NLD_2_1: 7.6[dB]
 
awk -F"[:[]" 'NF==1{print ; next}{if($2<14&&$2!=""){$0=$1":"$2"[dB]"; print $0}} ' input_File
1 Like

Unfortunately, neither code works for me. They kept printing only the first column.

Let me post the real file that I am using so you can try it also.

HTHa0101013>    ru
MOD_0_1:    20.5[dB]
MOD_1_1:    23.9[dB]
MOD_2_1:    Type
HTHa0101014>    ru
MOD_0_1:    26.2[dB]
MOD_1_1:    20.2[dB]
MOD_2_1:    27.8[dB]
HTHa0101015>    ru
MOD_0_1:    28.0[dB]
MOD_1_1:    24.2[dB]
MOD_2_1:    28.6[dB]
HTHa0101016>    ru
MOD_0_1:    24.6[dB]
MOD_1_1:    23.0[dB]
MOD_2_1:    27.6[dB]
HTHa0101017>    ru
MOD_0_1:    19.0[dB]
MOD_1_1:    18.4[dB]
MOD_2_1:    20.7[dB]
HTHa0101018>    ru
MOD_0_1:    24.9[dB]
MOD_1_1:    28.8[dB]
MOD_2_1:    22.3[dB]
HTHa0101020>    ru
MOD_0_1:    19.6[dB]
MOD_1_1:    23.2[dB]
MOD_2_1:    16.9[dB]
HTHa0101021>    ru
MOD_0_1:    19.1[dB]
MOD_1_1:    25.5[dB]
MOD_2_1:    27.5[dB]
HTHa0101022>    ru
MOD_0_1:    20.8[dB]
MOD_1_1:    20.0[dB]
MOD_2_1:    21.2[dB]

My expected output value is:

I used these codes:

wk -F"[:[]" ' { if (substr($0,0,3)=="HTHa010") print $0; else if ($2<14) print
$0}' tt > tt1.xls
wk -F"[:[]" 'NF==1{print ; next}{if($2<14&&$2!=""){$0=$1":"$2"[dB]"; print $0}}
 ' tt

Not getting the desired result.

The code from panyam

awk -F"[:[]" 'NF==1{print ; next}{if($2<14&&$2!=""){$0=$1":"$2"[dB]"; print $0}} '

Works, but in your example you don`t have value with lower than 14 dB. What exactly is the goal? If you want to see values for example < 30dB change the 14(bolded one) to 30 :slight_smile:

nawk -v thr=14 -F '[:[]' '/>/ {h=$0;p=1;next} {if(NF>2 &&$2<thr){printf("%s%s\n", p?h ORS:"", $0);p=0}}' myFile

Adjust the value of 'thr' to your liking.

Sorry, I posted the wrong input file again:
It was supposed to be this one

---------- Post updated at 04:44 PM ---------- Previous update was at 04:41 PM ----------

vgersh99,

Yours works. Great job guys. I appreciate you all.

Both works

-bash-3.2$ awk -F"[:[]" 'NF==1{print ; next}{if($2<14&&$2!=""){$0=$1":"$2"[dB]"; print $0}} ' test
HTHa0101013>    Value
MOD_2_1:        13.9[dB]
HTHa0101014>
MOD_1_1:        10.2[dB]
HTHa0101015>
HTHa0101016>
MOD_1_1:        13.0[dB]
HTHa0101017>
MOD_2_1:        10.7[dB]
HTHa0101018>
HTHa0101020>
MOD_1_1:        13.2[dB]
HTHa0101021>
HTHa0101022>
MOD_1_1:        10.0[dB]
MOD_2_1:        11.2[dB]
-bash-3.2$ cat test

HTHa0101013>    Value
MOD_0_1:        20.5[dB]
MOD_1_1:        23.9[dB]
MOD_2_1:        13.9[dB]
HTHa0101014>
MOD_0_1:        26.2[dB]
MOD_1_1:        10.2[dB]
MOD_2_1:        27.8[dB]
HTHa0101015>
MOD_0_1:        28.0[dB]
MOD_1_1:        24.2[dB]
MOD_2_1:        28.6[dB]
HTHa0101016>
MOD_0_1:        24.6[dB]
MOD_1_1:        13.0[dB]
MOD_2_1:        27.6[dB]
HTHa0101017>
MOD_0_1:        19.0[dB]
MOD_1_1:        18.4[dB]
MOD_2_1:        10.7[dB]
HTHa0101018>
MOD_0_1:        24.9[dB]
MOD_1_1:        28.8[dB]
MOD_2_1:        22.3[dB]
HTHa0101020>
MOD_0_1:        19.6[dB]
MOD_1_1:        13.2[dB]
MOD_2_1:        16.9[dB]
HTHa0101021>
MOD_0_1:        19.1[dB]
MOD_1_1:        15.5[dB]
MOD_2_1:        27.5[dB]
HTHa0101022>
MOD_0_1:        20.8[dB]
MOD_1_1:        10.0[dB]
MOD_2_1:        11.2[dB]
-bash-3.2$ awk -v thr=14 -F '[:[]' '/>/ {h=$0;p=1;next} {if(NF>2 &&$2<thr){printf("%s%s\n", p?h ORS:"", $0);p=0}}' test
HTHa0101013>    Value
MOD_2_1:        13.9[dB]
HTHa0101014>
MOD_1_1:        10.2[dB]
HTHa0101016>
MOD_1_1:        13.0[dB]
HTHa0101017>
MOD_2_1:        10.7[dB]
HTHa0101020>
MOD_1_1:        13.2[dB]
HTHa0101022>
MOD_1_1:        10.0[dB]
MOD_2_1:        11.2[dB]
-bash-3.2$

No, not really - look at the output of your script....