Problems to print specific lines with awk and grep...HELP!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problems to print specific lines with awk and grep...HELP!
# 1  
Old 08-01-2011
Problems to print specific lines with awk and grep...HELP!

Hi all

I have data like this:

Code:
model:    1,   misfit value:   0.74987
 
       1     1.182     1.735     2.056     1.867
 
       2     0.503     1.843     2.018     1.888
 
       3     2.706     2.952     2.979     1.882
 
       4     8.015     3.414     3.675     1.874
 
       5     1.557     3.745     3.238     1.776
 
       6     7.380     3.843     4.596     1.885
 
model:    2,   misfit value:   0.86908
 
       1     0.921     1.748     2.055     1.889
 
       2     0.402     2.465     1.913     1.808
 
       3     2.082     2.934     3.229     1.893
 
       4     9.872     3.294     3.747     1.704
 
       5     0.592     3.863     3.513     1.795
 
       6    16.299     4.028     4.551     1.890


and I want to print specific lines if a pattern occured. I've tried with awk and grep command but it doesn't work well.

I want to print the line with the misfit value and the next six lines if misfit value is less than some specific value. I tried with:

Code:
grep "misfit value" rfi_models | awk '{if ($5<0.8 print $0}'

but this print only the line with the misfit value.

Code:
grep -A6 -B1 "misfit value" rfi_models

and this print all the models without if statement...

Please can you suggest me something?

Thanks

Last edited by radoulov; 08-01-2011 at 11:29 AM.. Reason: Code tags, please!
# 2  
Old 08-01-2011
Assuming no blank lines between the records (unlike the provided sample):

Code:
awk '/misfit value/ && $5 > 0.8 { c = 7 } c && c--' infile

This User Gave Thanks to radoulov For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to print lines from a files with specific start and end patterns and pick only the last lines?

Hi, I need to print lines which are matching with start pattern "SELECT" and END PATTERN ";" and only select the last "select" statement including the ";" . I have attached sample input file and the desired input should be as: INPUT FORMAT: SELECT ABCD, DEFGH, DFGHJ, JKLMN, AXCVB,... (5 Replies)
Discussion started by: nani2019
5 Replies

2. Shell Programming and Scripting

How to print with awk specific field different from specific character?

Hello, i need help with awk. I have this file: cat number DirB port 67 er_enc_out 0 er_bad_os 0 DirB port 71 er_enc_out 56 er_bad_os 0 DirB port 74 er_enc_out 0 er_bad_os 0 DirB port 75 ... (4 Replies)
Discussion started by: elilmal
4 Replies

3. Shell Programming and Scripting

Print lines between two strings multiple occurencies (with sed, awk, or grep)

Hello, I can extract lines in a file, between two strings but only one time. If there are multiple occurencies, my command show only one block. Example, monfichier.txt contains : debut_sect texte L1 texte L2 texte L3 texte L4 fin_sect donnees inutiles 1 donnees inutiles 2 ... (8 Replies)
Discussion started by: theclem35
8 Replies

4. Shell Programming and Scripting

How to print the lines between the pattern using awk/grep/sed?

Hi, I need a help to search a pattern and print the multiple lines between them. Input file: Tue May 29 12:30:33 EDT 2012:threadWebContainer : 357:com.travimp.hotelierlinks.abba.service.RequestHandler.requestService(String, ITICSDataSet): hotelCancelReservation request: ... (4 Replies)
Discussion started by: aroragaurav.84
4 Replies

5. Shell Programming and Scripting

Print Specific lines when found specific character

Hello all, I have thousand file input like this: file1: $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$ | | | |$$ $$ UERT | TTYH | TAFE | FRFG |$$ $$______|______|________|______|$$ $$ | | | |$$ $$ 1 | DISK | TR1311 | 1 |$$ $$ 1 |... (4 Replies)
Discussion started by: attila
4 Replies

6. Shell Programming and Scripting

grep/awk to only print lines with two columns in a file

Hey, Need some help for command to print only lines with two columns in a file abc 111 cde 222 fgh ijk 2 klm 12 23 nop want the ouput to be abc 111 cde 222 ijk 2 Thanks a lot in advance!!! (3 Replies)
Discussion started by: leo.maveriick
3 Replies

7. Shell Programming and Scripting

iterate through list of numbers and print specific lines with awk

Could someone please point me in the right direction with the following? I have a program that generates logs that contains sections like this: IMAGE INPUT 81 0 0.995 2449470 0 1726 368 1 0.0635 0.3291 82 0 1.001 2448013 0 1666 365 1 0.0649 ... (4 Replies)
Discussion started by: euval
4 Replies

8. Shell Programming and Scripting

print first few lines, then apply regex on a specific column to print results.

abc.dat tty cpu tin tout us sy wt id 0 0 7 3 19 71 extended device statistics r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device 0.0 133.2 0.0 682.9 0.0 1.0 0.0 7.2 0 79 c1t0d0 0.2 180.4 0.1 5471.2 3.0 2.8 16.4 15.6 15 52 aaaaaa1-xx I want to skip first 5 line... (4 Replies)
Discussion started by: kchinnam
4 Replies

9. Shell Programming and Scripting

AIX equivalent to GNU grep's -B and -A [print lines after or before matching lines]

Hi folks I am not allowed to install GNU grep on AIX. Here my code excerpt: grep_fatal () { /usr/sfw/bin/gegrep -B4 -A2 "FATAL|QUEUE|SIGHUP" } Howto the same on AIX based machine? from manual GNU grep ‘--after-context=num’ Print num lines of trailing context after... (4 Replies)
Discussion started by: slashdotweenie
4 Replies

10. Shell Programming and Scripting

How to print specific lines with awk

Hi! How can I print out a specific range of rows, like "cat file | awk NR==5,NR==9", but in the END-statement? I have a small awk-script that finds specific rows in a file and saves the line number in an array, like this: awk ' BEGIN { count=0} /ZZZZ/ { list=NR ... (10 Replies)
Discussion started by: Bugenhagen
10 Replies
Login or Register to Ask a Question