![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to use sed modify specific lines | Jenny.palmy | UNIX for Dummies Questions & Answers | 5 | 05-18-2008 03:17 AM |
| How to print a specific page | randomcz | UNIX for Dummies Questions & Answers | 3 | 01-31-2007 11:03 AM |
| How to print at a specific position of the display | efernandes | Shell Programming and Scripting | 1 | 01-23-2007 04:08 PM |
| Print lines with search string at specific position | HealthyGuy | Shell Programming and Scripting | 4 | 12-04-2006 05:47 AM |
| Inserting specific lines in vi | giannicello | UNIX for Dummies Questions & Answers | 2 | 05-01-2002 05:10 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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[count]=NR counter++ } END { print "Total of:" count " rows." for (i in list) { print "Row: " list[i] ## Here, also print the actual row with linenr:list[i]. } } ' infile.txt Any help would be much appreciated. //Bugenhagen |
| Forum Sponsor | ||
|
|
|
|||
|
Print-outs in END
Hi!
Thank You for answering. I need to do the print-out in the END-statement, when NR is already at the last row. This is because my lineNr-array is quite large and every number is the begining of a group of rows that I need to print out. So if the array is: "120,140,166,178, ..." , I would need to decide in END how many stanzas that will be printed to a file. After that, I will take the next group of stanzas and print them to a new file. So is it possibe to do something like: "set NR=list[i]; print" //Bugenhagen |
|
|||
|
my opinion
Hi, i think what you want is difficult to realize.
1>the NR has gone to the last line. 2>At the END module for awk, it has gone to the end of the file, so you can not re-hold the line of the file So,my suggestion for you is: 1> try to remember all the desired rows in first awk 2>awk again |
|
|||
|
Sample
Hi!
Input file is from AIX/nmon. (This is a cut-down version) ----------------------------------------------------- AAA,progname,nmon_aix53# <-------Header starts here AAA,command,/usr/local/bin/nmon_aix53 -f -t -s 10 -c 8640 AAA,version,v10r AAA,build,AIX53 AAA,disks_per_line,150 BBBB,0026,hdisk31,unknown,Hitachi-HDS BBBB,0027,hdisk32,unknown,Hitachi-HDS BBBC,014,LV NAME LPs PPs DISTRIBUTION MOUNT POINT BBBC,015,hd2 28 28 28..00..00..00..00 /usr BBBP,2523,oslevel ZZZZ,T0001,00:11:18,25-JUL-2007# <----------Body starts here CPU01,T0001,32.9,19.0,11.7,36.5 CPU02,T0001,0.9,0.7,0.2,98.1 CPU03,T0001,53.3,10.5,5.6,30.6 CPU04,T0001,0.1,0.6,0.0,99.3 CPU05,T0001,31.2,5.1,0.7,63.1 ZZZZ,T0003,00:11:38,25-JUL-2007# <----------Next stanza in body CPU01,T0003,44.3,4.3,0.6,50.8 CPU02,T0003,0.0,0.0,0.0,100.0 CPU03,T0003,45.2,0.0,0.0,54.8 CPU04,T0003,0.0,0.0,0.0,100.0 CPU05,T0003,19.7,0.0,0.0,80.3 BBBP,2524,ending vmstat -v# <----------------Footer starts here BBBP,2525,ending vmstat -v," 20709370 memory pages" BBBP,2526,ending vmstat -v," 19954046 lruable pages" BBBP,2527,ending vmstat -v," 748541 free pages" -------------------------------------------------------- So I would like to: Put header in file1. Put all stanzas (starting with ZZZZ) for a specific hour in file1. Put footer in file1. Next. Put header in file2. Put all stanzas for next hour in file2. Put footer in file2. Cont. until EOF. //Br Bugenhagen |
|||
| Google UNIX.COM |