Sponsored Content
Top Forums Shell Programming and Scripting print first few lines, then apply regex on a specific column to print results. Post 302447877 by durden_tyler on Tuesday 24th of August 2010 02:23:14 PM
Old 08-24-2010
Quote:
Originally Posted by kchinnam
abc.dat
Code:
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 headers. Then select rows with column 11 starts with 'aaaaaa1'.
...

Code:
$
$
$ cat 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
$
$
$ perl -lane '$.>5 && print if $F[10] =~ /^aaaaaa1/' abc.dat
0.2 180.4 0.1 5471.2 3.0  2.8  16.4  15.6   15 52 aaaaaa1-xx
$
$
$ awk 'NR>5 && $11 ~ /^aaaaaa1/' abc.dat
0.2 180.4 0.1 5471.2 3.0  2.8  16.4  15.6   15 52 aaaaaa1-xx
$
$

Ok, seems like I misread it.
If you want to print the first 5 lines and apply the condition from line 6 onwards then -

Code:
$
$
$ perl -lane 'print if $.>5 && $F[10] =~ /^aaaaaa1/ || $.<=5' 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.2 180.4 0.1 5471.2 3.0  2.8  16.4  15.6   15 52 aaaaaa1-xx
$
$
$
$ awk 'NR<=5 || NR>5 && $11 ~ /^aaaaaa1/' 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.2 180.4 0.1 5471.2 3.0  2.8  16.4  15.6   15 52 aaaaaa1-xx
$
$

tyler_durden

Last edited by durden_tyler; 08-24-2010 at 03:30 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Question about sort specific column and print other column at the same time !

Hi, This is my input file: ali 5 usa abc abu 4 uk bca alan 6 brazil bac pinky 10 utah sdc My desired output: pinky 10 utah sdc alan 6 brazil bac ali 5 usa abc abu 4 uk bca Based on the column two, I want to do the descending order and print out other related column at the... (3 Replies)
Discussion started by: patrick87
3 Replies

2. Shell Programming and Scripting

Print lines after regex

Hello, I need to print four lines inmediatly after the regexp, but not the line containing the regexp. The print should show the four lines together in one. Thanks! (13 Replies)
Discussion started by: auratus42
13 Replies

3. Shell Programming and Scripting

Print lines that match regex on xth string

Hello, I need an awk command to print only the lines that match regex on xth field from file. For example if I use this command awk -F"|" ' $22 == "20130117090000.*" 'It wont work, I think, because single quotes wont allow the usage of the metacharacter star * . On the other hand I dont know... (2 Replies)
Discussion started by: black_fender
2 Replies

4. Shell Programming and Scripting

To print lines between 2 timestamps using awk|sed and regex

Hi, I am using the following code to fetch lines that are generated in last 1 hr . Hence, I am using date function to calculate -last 1 hr & the current hr and then somehow use awk (or sed-if someone could guide me better) with some regex pattern. dt_1=`date +%h" "%d", "%Y\ %l -d "1 hour... (10 Replies)
Discussion started by: sarah-alikhan31
10 Replies

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

6. Shell Programming and Scripting

Print lines that contain a value in a specific column shared by more than 1 entity in another col

I want to expand on a question that I just asked here: I want to extract only those values in Column 2 that are shared by at least 2 unique values in Column 2. Using the same input (in this case 3- tab-separated columns): waterline-n below-sheath-v 14.8097 dock-n below-sheath-v ... (2 Replies)
Discussion started by: owwow14
2 Replies

7. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

8. Shell Programming and Scripting

How to print multiple specific column after a specific word?

Hello.... Pls help me (and sorry my english) :) So I have a file (test.txt) with 1 long line.... for example: isgc jsfh udgf osff 8462 error iwzr 653 idchisfb isfbisfb sihfjfeb isfhsi gcz eifh How to print after the "error" word the 2nd 4th 5th and 7th word?? output well be: 653 isfbisfb... (2 Replies)
Discussion started by: marvinandco
2 Replies

9. Shell Programming and Scripting

Parsing OSX UNIX command results which print in multiple lines

from the CLI on a Mac, if you type networksetup -listallnetworkservices then you get results in a multi-line paragraph that look something like this: networksetup -listallnetworkservices An asterisk (*) denotes that a network service is disabled. Wi-Fi Display Ethernet Bluetooth DUN... (7 Replies)
Discussion started by: hungryd
7 Replies

10. Shell Programming and Scripting

(n)awk: print regex search output lines in one line

Hello. I have been looking high and low for the solution for this. I seems there should be a simple answer, but alas. I have a big xml file, and I need to extract certain information from specific items. The information I need can be found between a specific set of tags. let's call them... (2 Replies)
Discussion started by: Tobias-Reiper
2 Replies
ppdof(8)						      System Manager's Manual							  ppdof(8)

NAME
ppdof - Text to PostScript translation filter SYNOPSIS
/usr/lbin/ppdof +Cfilename [-n login] [-h host] [...] OPTIONS
Use of the print flags is dependent on the features available on the print device, and on the current status of those features. For exam- ple, when you select a particular paper size, the appropriate paper must be correctly loaded in the paper trays. Options in /etc/printcap The following options are set in the /etc/printcap file and can be specified using the + switch. For example: :if=/usr/lbin/ppdof +Bupper +Cln32.rpd: You can also specify command line options in the /etc/printcap file using the + switch. For example: :if=/usr/lbin/ppdof +Olandscape +Cln32.rpd: Here, the -Olandscape option is specified. Specifies the default tray name to select for printing the banner page. For example: :of=/usr/lbin/ppdof +Bupper +Cln32.rpd: In this example, the banner page will be printed on whatever stock is currently loaded into the upper tray on the selected print device. Specifies the printer configuration file to use for the print job. Specifies the unit of measurement to be inches or cen- timeters for lines per inch (lpi), characters per inch (cpi), and page margin options. The default value is inches. Specifies the default tray name to select for printing the trailer page. For example: :if=/usr/lbin/ppdof +olower +Cln32.rpd: Command Line Options Specify print filter options at the command line using the lpr command as follows. Multiple -O options are supported. Specifies the host name from which the job owner is submitting the print command. Specifies the login (account) name of the job owner. Specifies the name of the output tray where the printed pages are placed. Specifies the page width in columns for portrait and landscape printing. A page width of 0 instructs the filter to use 80 columns in portrait orientation and 132 columns in landscape orientation. Specifies the tray name from which print paper is selected. The printer may select an alternate tray when the paper size provided in the tray does not match the docu- ment requirements. Specifies the number of sides to print on each sheet. You can specify sides as follows: 1 or one - Print on one side of the sheet. 2 or two - Print on both sides of the sheet (duplex printing). Specifies options related to page orientation, formatting, and features as follows: Specifies the number of characters to print per inch. Specifies only even numbered sheets are to be printed. Speci- fies the printed output is parallel to the long side of the page. Specifies the number of lines to print per page. Specifies the number of lines to print per inch. Specifies only odd numbered sheets are to be printed. Specifies the range of pages to be printed, starting with page number m and ending with page number n. Specifies to print the list of options provided by the printer configuration file which includes paper sizes, input and output paper tray names. For example: # lpr -Oprint /etc/motd (Note that the file /etc/motd is specified to satisfy lpr command line requirements, the file itself is not printed.) Specifies the printed output is parallel to the short side of the page. These options specify the various page margins in inches. The page mar- gin sizes in inches as follows: tm= - Top margin in inches. For example -Otm=2 bm= - Bottom margin in inches. For example -Obm=1.5 lm= - Left margin in inches. For example -Olm=1 rm= - Right margin in inches. For example -Orm=3 pm= - Page margin. Using this option sets tm, bm, lm and rm to the same value. For example -Opm=1.25 When configuring the /etc/printcap entry, different margins for landscape and portrait orientation can be specified by adding the suffixes _l and _p respectively. For example: :if=/usr/lbin/ppdof +Olm_p=0.5 +Olm_l=0.25 +Cln32.rpd: DESCRIPTION
The ppdof filter translates ASCII to PostScript and handles the device dependencies of a PostScript printer. It is recommended that the ppdof filter be specified for both the :of and the :if fields in the /etc/printcap file. For a description of these fields, see the printcap(4) reference page. RESTRICTIONS
The commands generated by the ppdof filter to handle device dependencies might be incompatible with some PostScript documents. When a PostScript file does not print correctly use the following command to prevent file preprocessing. # lpr -x file.ps The filter will not setup device dependencies or provide ASCII to PostScript translation for documents containing printer control charac- ters. EXIT STATUS
Any value other than zero (0) indicates that an error has occurred. ERRORS
Use the lf error log field in the /etc/printcap to specify the name of the error log file. SEE ALSO
Commands: cancel(1), lpr(1), pr(1) Files: printcap(4). System Administration ppdof(8)
All times are GMT -4. The time now is 12:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy