Retrieving a specific value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Retrieving a specific value
# 1  
Old 06-06-2011
Retrieving a specific value

I have this input file:
Quote:
wow1>
NLD_0_1: 20.5[dB]
NLD_1_1: 23.9[dB]
NLD_2_1: 12.3
wow4>
NLD_0_1: 26.2[dB]
NLD_1_1: 9.2[dB]
NLD_2_1: 27.8[dB]
wow15>
NLD_0_1: 28.0[dB]
NLD_1_1: 24.2[dB]
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]
I want to get the following output file:
Output
Quote:
wow1>
NLD_2_1: 12.3[dB]
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]
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!
# 2  
Old 06-06-2011
Code:
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]

# 3  
Old 06-06-2011
Code:
 
awk -F"[:[]" 'NF==1{print ; next}{if($2<14&&$2!=""){$0=$1":"$2"[dB]"; print $0}} ' input_File

This User Gave Thanks to panyam For This Post:
# 4  
Old 06-06-2011
Unfortunately, neither code works for me. They kept printing only the first column.
Quote:
HTHa0101013> Value
HTHa0101014>
HTHa0101015>
HTHa0101016>
HTHa0101017>
HTHa0101018>
HTHa0101020>
HTHa0101021>
HTHa0101022>
Let me post the real file that I am using so you can try it also.
Code:
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:
Quote:
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]
I used these codes:
Code:
wk -F"[:[]" ' { if (substr($0,0,3)=="HTHa010") print $0; else if ($2<14) print
$0}' tt > tt1.xls

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

Not getting the desired result.

Last edited by radoulov; 06-06-2011 at 05:29 PM.. Reason: Code tags.
# 5  
Old 06-06-2011
The code from panyam

Code:
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 Smilie
# 6  
Old 06-06-2011
Code:
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.
# 7  
Old 06-06-2011
Sorry, I posted the wrong input file again:
It was supposed to be this one
Quote:
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]
---------- Post updated at 04:44 PM ---------- Previous update was at 04:41 PM ----------

vgersh99,

Yours works. Great job guys. I appreciate you all.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Passing argument not retrieving.

Hi I have a script which am trying to pass an argument which am trying to call using $1 but its not taking the value inside the if loop as it showing the error as if: Empty if.. Any help on this will be helpful. #!/usr/bin/csh echo $1 if ('$1' == "pp") then echo "Printing $1" endif (4 Replies)
Discussion started by: rogerben
4 Replies

2. UNIX for Dummies Questions & Answers

retrieving data between two strings

I have input file like AAA AAA CCC CCC CCC EEE EEE EEE EEE FFF FFF GGG GGG i was trying to retrieve data between two strings using sed. sed -n /CCC/,/FFF/p input_file Am getting output like CCC CCC CCC (22 Replies)
Discussion started by: NareshN
22 Replies

3. Shell Programming and Scripting

Retrieving File name

Hi All.. I have a Filename as FAB1_600015_CONRAD.A0_7XYZ12345.000_LT-SWET.01_LTPA25L_20110622-161429_07_WFR12345_20110622-161429_20110712-125228.data.dis I want to get the result as... (5 Replies)
Discussion started by: asheshrocky
5 Replies

4. Shell Programming and Scripting

error in retrieving records from DB

Hi ., I have 3 records in a oracle table... wen i connect to oracle from unix environment and query the table i get some errors... the script i used is g=`sqlplus -s "username/password" << EOF select column from table; EOF` if then echo $g fi The output i get... (1 Reply)
Discussion started by: cratercrabs
1 Replies

5. Shell Programming and Scripting

retrieving specific lines from a file - can I use grep ?

Hi there, if i had a file that looked like this my_server1 red green blue yellow blue my_server2 blue blue yellow green blue my_server3 yellow (9 Replies)
Discussion started by: hcclnoodles
9 Replies

6. Solaris

help retrieving files from SunOS 5.8

Hi, I am trying to get a small amount of files off of a SunBlade 2000 running SunOS 5.8, but I'm having trouble finding a medium that will actually work. It is not networked, and it doesn't have a writable CD drive. My only options seem to be floppy disk and USB drive. However, when I insert... (11 Replies)
Discussion started by: ryanm
11 Replies

7. UNIX for Dummies Questions & Answers

retrieving files which has more than 0 bytes

Hi, Can anyone tell how to list all files in current directory which has more than 0 bytes? (4 Replies)
Discussion started by: sri2005
4 Replies

8. UNIX for Dummies Questions & Answers

Retrieving data

Friends, I have a data with 3 columns: 30 41 1 39 19 4 14 25 3 .... .... ..... I want to retrieve any data in the first column that is greater 15. What is the best way to do this? Thanks! (2 Replies)
Discussion started by: bobo
2 Replies

9. UNIX for Dummies Questions & Answers

Retrieving output interactively

Hi. I have a situation where I need to constantly read a command's output in order to loop through it to determine something that is happening over our system. The command td <filename> interactively prints 'filename' as text is written to it and this is redirected to standard output. I have been... (8 Replies)
Discussion started by: fidodido
8 Replies

10. AIX

doubt in retrieving date

Hello, instead of specifying the date manually in the list as below, for dt in 010106 010206 010306 010406 010506 010606 here for example : 010106 - 1st jan 2006 how to retrieve the date of a week automatically and put in a loop? is there any way to do? thanks in advance. (1 Reply)
Discussion started by: sumi
1 Replies
Login or Register to Ask a Question