How to grab the value of field before the line reached


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to grab the value of field before the line reached
# 1  
Old 03-28-2008
How to grab the value of field before the line reached

Hi.

I have a qury whihc I hope someone could clarify.

I have a file:-

Num Measure
108 0.05
12 0.45
13 0.2
19 0.5

I wanted to grep the value of 19 from Column Num which will then take the minimum value of measure (not including 19's measure value). Means in this case, i am hoping to get 0.05 as the mininum of (0.05,0.45 and 0.2) right before the entry 19. Anyone could advise me on this?


Thanks and appreciate alot.
# 2  
Old 03-28-2008
Please provide us with a sample output and make it clear..

Regards,
aajan
# 3  
Old 03-28-2008
Hi

Means I have a file called test.txt

with:-
Num Measure
108 0.05
12 0.45
13 0.2
19 0.5

And in my bash I will grep a random number which match the Num column in test.txt. (e.g getting random number of Num value of 2,4,6,8,10,12) from test.txt. In test.txt, the element 12 of Num matches with the random number which I wanted to retrieve.This step i think should be find by grep command.

Next, I would like to find the minimum of measure before the element num 12 and measure 0.45 line. In this case, the output would be 0.05 since only one element is there ebfore the Num 12 and measure 0.45.

Another example; let say my random number to retrieve is 19 of test.txt. I I wanted to find the elements of Measure which gives the minimum value.

In this example; the possible value to be minimum (not including the measure which belongs to random number) are:-
0.05,0.45,0.2
Final output would be 0.05 since its the minimum among these 3 values.

Hope i dont confused you. Feel free to let me know if youre still unsure. Thanks.
# 4  
Old 03-28-2008
Write an awk script which remembers the lowest value so far and stops when it sees the desired key. The keys would be $1 and values would be $2.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grab text after pattern on the same line

data: 8iW5iPACIb5fafafEU24f3EOOjpakx6VwxBX+NafafxJMWX8iW5iPACIb5fafafEU24f3EOOjpakx6VwxBX+NafafxJMWX8iW5i PACIb5fafafEU24f3EOOjpakx6VwxBX+NafafxJMWX8iW5iPACIb5fafafEU24f3EOOjpakx6VwxBX+ 8nwR15UzfeZafaf2bGr8akx6VwxBX+NafafxJMWX8iW5iPACIb5fafafEU24f3EOOjp lVpOoMLXJ ... (19 Replies)
Discussion started by: SkySmart
19 Replies

2. Shell Programming and Scripting

Command/script to match a field and print the next field of each line in a file.

Hello, I have a text file in the below format: Source Destination State Lag Status CQA02W2K12pl:D:\CAQA ... (10 Replies)
Discussion started by: pocodot
10 Replies

3. Shell Programming and Scripting

Grab line regardless of if it ends with tabs or spaces

so i have a data file that has various lines which may or may not end with spaces or tabs. data.file: , \t \t {sample} <spaces> <spaaces> several more spaces.... {"resemble"}, <nospaces> Command i'm using: sed -n 8p data.file | egrep "\],$|\],\ $" or egrep "\],$|\],\ $"... (1 Reply)
Discussion started by: SkySmart
1 Replies

4. Shell Programming and Scripting

grep grab 19 letters from now or a full line

Hi, I have a file like this >hg19_chr1_123_456_+ asndbansbdahsjdbfsjhfghjdsghjdghjdjhdghjjdkhfsdkjfhdsjkdkjghkjdhgfjkhjfkf hasjgdhjsgfhjdsgfdsgfjhdgjhdjhdhjdfhjdfjgfdfbdghjbfjksdhfjsfdghjgdhjgfdjhgd jhgdfj >hg19_chr1_123_456_-... (5 Replies)
Discussion started by: jacobs.smith
5 Replies

5. Shell Programming and Scripting

Grep the word from pattern line and update in subsequent lines till next pattern line reached

Hi, I have got the below requirement. please suggest. I have a file like, Processing Item is: /data/ing/cfg2/abc.txt /data/ing/cfg3/bgc.txt Processing Item is: /data/cmd/for2/ght.txt /data/kernal/config.klgt.txt I want to process the above file to get the output file like, ... (5 Replies)
Discussion started by: rbalaj16
5 Replies

6. Shell Programming and Scripting

Compare Field in Current Line with Field in Previous

Hi Guys I have the following file Essentially, I am trying to find the right awk/sed syntax in order to produce the following 3 distinct files from the file above: Basically, I want to print the lines of the file as long as the second field of the current line is equal to the... (9 Replies)
Discussion started by: moutaye
9 Replies

7. Shell Programming and Scripting

Grab first or second line after a search string

In a shell script, I need to grab the first or second line after a search string in a file. For example: File.out: Random Info Manufacturer: XYZPDQ System Info Manufacturer: Hewlett-Packard Product Name: ProLiant I search for the word FILE, I want to be able to grab the line... (1 Reply)
Discussion started by: jwk1230
1 Replies

8. Shell Programming and Scripting

grab the line using awk

suppose u have a file AAAAAKKSKSKMSKMSKBNNSHNKSNJNMSYNMSBH This is exactly wht the input is like Question is i want to list wht is on the line 5 tht will be A but Remember u want to extract in between say from 100 to 300 i tried using awk 'BEGIN {FS=""} {print$100,$300}' file but it will... (1 Reply)
Discussion started by: cdfd123
1 Replies

9. Shell Programming and Scripting

grab next consecutive line or lines

Hello i'm writting a krn shell that will find the letter F and I would like to grab everything from F till 0:00. Is there a sed or awk command that i could use. Thank you. File is looks like this. 11/12 xxx xxxx xxx F xxxx xxxx some info entered here some info entered here xxxx... (1 Reply)
Discussion started by: wisher115
1 Replies

10. Shell Programming and Scripting

find 2 line numbers, grab text in between

hi, i have a large text file that I just want to extract the important information from. It will be a random number of lines but between two specific line numbers/markers. I was thinking I could get the line number for the first marker: Tablespace Percent Total Free Then get the line... (11 Replies)
Discussion started by: Da_Duck
11 Replies
Login or Register to Ask a Question