AWK and print next lines #3 thru #10


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK and print next lines #3 thru #10
# 1  
Old 08-16-2012
AWK and print next lines #3 thru #10

I have a output log file, that I want to extract some temperature measurement data.

I want to AWK on the words "show chassis environment" in the original file, and extract that entire line, and then the 3rd to 10th lines after the one I AWK'd, into a seperate output file.

Here is an example of the information in the source file :

Code:
20:52:34_23C | root@HWTestEng-Gext% 
20:52:35_23C | 
20:52:35_23C | root@HWTestEng-Gext% cli show chassis environment
20:52:35_23C | 
20:52:35_23C | Class Item                           Status     Measurement
20:52:36_23C |       PCB Left                       OK         33 degrees C / 91 degrees F
20:52:36_23C |       SFP+ Xcvr                      OK         33 degrees C / 91 degrees F
20:52:36_23C |       FEB                            OK         50 degrees C / 122 degrees F
20:52:36_23C |       PCB Up                         OK         33 degrees C / 91 degrees F
20:52:36_23C |       PCB Mid                        OK         36 degrees C / 96 degrees F
20:52:36_23C |       Telecom Mod                    OK         37 degrees C / 98 degrees F
20:52:36_23C |       Routing Engine                 OK         31 degrees C / 87 degrees F
20:52:36_23C |       Heater off                    
20:52:36_23C | root@HWTestEng-Gext%

the information I want to extract and export to another file would be:


Code:
20:52:35_23C | root@HWTestEng-Fortius-Gext% cli show chassis environment
 20:52:36_23C |       PCB Left                       OK         33 degrees C / 91 degrees F
20:52:36_23C |       SFP+ Xcvr                      OK         33 degrees C / 91 degrees F
20:52:36_23C |       FEB                            OK         50 degrees C / 122 degrees F
20:52:36_23C |       PCB Up                         OK         33 degrees C / 91 degrees F
20:52:36_23C |       PCB Mid                        OK         36 degrees C / 96 degrees F
20:52:36_23C |       Telecom Mod                    OK         37 degrees C / 98 degrees F
20:52:36_23C |       Routing Engine                 OK         31 degrees C / 87 degrees F
20:52:36_23C |       Heater off

Moderator's Comments:
Mod Comment Please view this code tag video for how to use code tags when posting code and data.

Last edited by Corona688; 08-16-2012 at 04:25 PM..
# 2  
Old 08-16-2012
Does this work for you?
(And yes, I know I can get rid of that useless 'cat'!!)

Code:
$ cat sample1.txt | grep "show chassis" -A10 | grep -e "degrees" -e "chassis"
20:52:35_23C | root@HWTestEng-Gext% cli show chassis environment
20:52:36_23C |       PCB Left                       OK         33 degrees C / 91 degrees F
20:52:36_23C |       SFP+ Xcvr                      OK         33 degrees C / 91 degrees F
20:52:36_23C |       FEB                            OK         50 degrees C / 122 degrees F
20:52:36_23C |       PCB Up                         OK         33 degrees C / 91 degrees F
20:52:36_23C |       PCB Mid                        OK         36 degrees C / 96 degrees F
20:52:36_23C |       Telecom Mod                    OK         37 degrees C / 98 degrees F
20:52:36_23C |       Routing Engine                 OK         31 degrees C / 87 degrees F

# 3  
Old 08-16-2012
YES - That Works !!! Thanks !
# 4  
Old 08-16-2012
AWK:
Code:
awk '/show chassis environment/&&p=1;p&&p++>3&&p<13' file

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print all lines in a row except the last one with awk

Hi again, is it possible to do the following using awk? input file is 4.465E+17 5.423E+16 1.218E+17 2.600E+16 9.135E+15 1.238E+14 ... 6.238E+14 desired output 4.465E+17 & 5.423E+16 & 1.218E+17 & 2.600E+16 & 9.135E+15 & 1.238E+14 & ... & (3 Replies)
Discussion started by: f_o_555
3 Replies

2. Shell Programming and Scripting

Print values within groups of lines with awk

Hello to all, I'm trying to print the value corresponding to the words A, B, C, D, E. These words could appear sometimes and sometimes not inside each group of lines. Each group of lines begins with "ZYX". My issue with current code is that should print values for 3 groups and only is... (6 Replies)
Discussion started by: Ophiuchus
6 Replies

3. UNIX for Dummies Questions & Answers

awk - (URGENT!) Print lines sort and move lines if match found

URGENT HELP IS NEEDED!! I am looking to move matching lines (01 - 07) from File1 and 77 tab the matching string from File2, to File3.txt. I am almost done but - Currently, script is not printing lines to File3.txt in order. - Also the matching lines are not moving out of File1.txt ... (1 Reply)
Discussion started by: High-T
1 Replies

4. UNIX for Dummies Questions & Answers

How to print results from two lines using awk?

I need to print a specific string from an html file that's always occurring between two other known strings. Example: from the text below, I would like to print the bolded part: <this is a lot of text before the string I want to print> fullpath: abc/def/ghi/example.xlf -cfver. <sample text... (15 Replies)
Discussion started by: danegon
15 Replies

5. Shell Programming and Scripting

awk print lines in a file

Dear All, a.txt A 1 Z A 1 ZZ B 2 Y B 2 AA how can i use awk one line to achieve the result: A Z|ZZ B Y|AA Thanks (5 Replies)
Discussion started by: jimmy_y
5 Replies

6. UNIX for Dummies Questions & Answers

Awk print all lines on match?

Ok so I can use awk to match a pattern and print the whole line with print $0. Is there any way to just tell awk to print every line of output when the pattern matches? I'm having it wait for the word error and then print that entire line. But what I actually need to see is all the following... (9 Replies)
Discussion started by: MrEddy
9 Replies

7. UNIX for Dummies Questions & Answers

print multiple lines with awk

Hi everyone! I'm not new to Unix, but I've never used awk before. I tried to look up this information on several sites and forums, I also looked in the documentation but I haven't found a solution yet. I would like to print the previous 3 lines before and the following 4 lines after the... (6 Replies)
Discussion started by: djcsabus
6 Replies

8. Shell Programming and Scripting

How to print only lines in between two strings using awk

Hi, I want to print only lines in between two strings and not the strings using awk. Eg: OUTPUT top 2 bottom 1 left 0 right 0 page 66 END I want to print into a new file only top 2 bottom 1 left 0... (4 Replies)
Discussion started by: jisha
4 Replies

9. 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

10. Shell Programming and Scripting

How to print number of lines with awk ?

Can some body tell me how to print number of line from a particular file, with sed. ? Input file format AAAA BBBB CCCC SDFFF DDDD DDDD Command to print line 2 and 3 ? BBBB CCCC And also please tell me how to assign column sum to variable. I user the following command it... (1 Reply)
Discussion started by: maheshsri
1 Replies
Login or Register to Ask a Question