How to print line if field matches?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to print line if field matches?
Prev   Next
# 1  
Old 09-02-2010
How to print line if field matches?

Hi all,

I got several lines line this
a b c d e 1 e
a 1 c d e 3 f
a b c 1 e 8 h
a b c d e 1 w
a 1 c d e 2 w
a b c d e 1 t
a b c d e 7 4

How can I print the line if 1 is the field one before the last field?
Basicly this 2 field ?
a b c d e 1 e
a b c d e 1 t

The file I got is huges.

Thanks
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print line if values in fields matches number and text

datafile: 2017-03-24 10:26:22.098566|5|'No Route for Sndr:RETEK RMS 00040 /ZZ Appl:PF Func:PD Txn:832 Group Cntr:None ISA CntlNr:None Ver:003050 '|'2'|'PFI'|'-'|'EAI_ED_DeleteAll'|'EAI_ED'|NULL|NULL|NULL|139050594|ActivityLog| 2017-03-27 02:50:02.028706|5|'No Route for... (7 Replies)
Discussion started by: SkySmart
7 Replies

2. Shell Programming and Scripting

Print whole line if variables matches

Der colleagues, 4 days I am trying to solve my issue and no success.. Maybe you can give me a clue how to achieve what I need.. So I have two files. file1 example: 1_column1.1 1_column2.1 aaa 1_column4.1 1_column1.2 1_column2.2 ttt 1_column4.2 1_column1.3 1_column2.3 ... (10 Replies)
Discussion started by: nypreH
10 Replies

3. Linux

Print line 1 if line 3 matches of the output

Hi I want to extend following command so that on the basis of "Branch: ****" on the third line I can grep and print name of the file on the first line. cat .labellog.emd | grep DA2458A7962276A7E040E50A0DC06459 | cut -d " " -f2 | grep -v branch_name | xargs -I file <command to describe> file ... (1 Reply)
Discussion started by: ezee
1 Replies

4. Shell Programming and Scripting

How to print line if two lines above it matches patterns.?

Hi, I could only find examples to print line before/after a match, but I'd need to print line after two separate lines matching. E.g.: From the below log entry, I would need to print out the 1234. This is from a huge log file, that has a lot of entries with "CLIENT" and "No" entries (+ other... (3 Replies)
Discussion started by: Juha
3 Replies

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

6. Shell Programming and Scripting

awk to print the line that matches and the next if line is wrapped

I have a file and when I match the word "initiators" in the first column I need to be able to print the rest of the columns in that row. This is fine for the most part but on occasion the "initiators" line gets wrapped to the next line. Here is a sample of the file. caw-enabled ... (3 Replies)
Discussion started by: kieranfoley
3 Replies

7. Shell Programming and Scripting

Using regex's from file1, print line and line after matches in file2

Good day, I have a list of regular expressions in file1. For each match in file2, print the containing line and the line after. file1: file2: Output: I can match a regex and print the line and line after awk '{lines = $0} /Macrosiphum_rosae/ {print lines ; print lines } ' ... (1 Reply)
Discussion started by: pathunkathunk
1 Replies

8. UNIX for Advanced & Expert Users

Print line if subsrt matches array

Hi Folks! im printing all lines where the characters in position 270-271 match 33|H1|HA|KA|26 so i came up with this #!/bin/bash array=(33 H1 HA KA 26 ) for i in "${array}" do #echo $i awk '{ if (substr($0,270,2)~'/$i/') print; }' $1 >> $1.temp done It works fine . but... (2 Replies)
Discussion started by: phpsnook
2 Replies

9. Shell Programming and Scripting

Print line if first Field matches a pattern

Hi All, I would like my code to be able to print out the whole line if 1st field has a dot in the number. Sample input and expected output given below. My AWK code is below but it can;t work, can any expert help me ? Thanks in advance. {if ($1 ~ /*\.*/) { print $0 }} Input: ... (2 Replies)
Discussion started by: Raynon
2 Replies

10. Shell Programming and Scripting

print next line if matches a particular word..need help

Hi i need a help for making a script whch can print next line if it matches a particular word like file1 have ename Mohan eid 2008 ename Shyam eid 345 if scipt got Mohan it will print next line (eid 2008) pls help me .......:) (2 Replies)
Discussion started by: anish19
2 Replies
Login or Register to Ask a Question
INNWATCH.CTL(5) 						File Formats Manual						   INNWATCH.CTL(5)

NAME
innwatch.ctl - control Usenet supervision by innwatch DESCRIPTION
The file /etc/news/innwatch.ctl is used to determine what actions are taken during the periodic supervisions by innwatch. The file consists of a series of lines; blank lines and lines beginning with a number sign (``#'') are ignored. All other lines consist of seven fields, each preceded by a delimiting character: :label:state:condition:test:limit:command:reason The delimiter can be any one of several non-alphanumeric characters that does not appear elsewhere in the line; there is no way to quote it to include it in any of the fields. Any of ``!'', ``,'', ``:'', ``@'', ``;'', or ``?'' is a good choice. Each line can have a different delimiter; the first character on each line is the delimiter for that line. White space surrounding delimiters, except before the first, is ignored, and does not form part of the fields, white space within fields is permitted. All delimiters must be present. The first field is a label for the control line. It is used as an internal state indicator and in ctlinnd messages to control the server. If omitted, the line number is used. The second field specifies when this control line should be used. It consists of a list of labels, and special indicators, separated by whitespace. If the current state matches against any of the labels in this field, this line will be used as described below. The values that may be used are: - This line matches if the current state is the same as the label on this line, or if the current state is ``run,'' the initial state. This is also the default state if this field is empty. + This line matches if the current state is ``run.'' * This line always matches. label This line matches if the current state is the specified ``label.'' -label This line matches if the current state is not the specified ``label.'' The third field specifies a shell command that is invoked if this line matches. Do not use any shell filename expansion characters such as ``*'', ``?'', or ``['' (even quoted, they're not likely to work as intended). If the command succeeds, as indicated by its exit status, it is expected to have printed a single integer to standard output. This gives the value of this control line, to be used below. If the com- mand fails, the line is ignored. The command is executed with its current directory set to the news spool directory, /var/spool/news. The fourth field specifies the operator to use to test the value returned above. It should be one of the two letter numeric test operators defined in test(1) such as ``eq'', ``lt'' and the like. The leading dash (`'-'') should not be included. The fifth field specifies a constant with which to compare the value using the operator just defined. This is done by invoking the command test value -operator constant The line is said to ``succeed'' if it returns true. The sixth field specifies what should be done if the line succeeds, and in some cases if it fails. Any of the following words may be used: throttle Causes innwatch to throttle the server if this line succeeds. It also sets the state to the value of the line's label. If the line fails, and the state was previously equal to the label on this line (that is, this line had previously succeeded), then a go command will be sent to the server, and innwatch will return to the ``run'' state. The ``throttle'' is only performed if the current state is ``run'' or a state other than the label of this line, regardless of whether the command succeeds. pause Is identical to ``throttle'' except that the server is paused. shutdown Sends a ``shutdown'' command to the server. It is for emergency use only. flush Sends a ``flush'' command to the server. go Causes innwatch to send a ``go'' command to the server and to set the state to ``run.'' exit Causes innwatch to exit. skip The result of the control file is skipped for the current pass. The last field specifies the reason that is used in those ctlinnd commands that require one. More strictly, it is part of the reason -- innwatch appends some information to it. In order to enable other sites to recognize the state of the local innd server, this field should usually be set to one of several standard values. Use ``No space'' if the server is rejecting articles because of a lack of filesystem resources. Use ``loadav'' if the server is rejecting articles because of a lack of CPU resources. Once innwatch has taken some action as a consequence of its control line, it skips the rest of the control file for this pass. If the action was to restart the server (that is, issue a ``go'' command), then the next pass will commence almost immediately, so that innwatch can discover any other condition that may mean that the server should be suspended again. EXAMPLES
@@@df .|awk 'NR==2 {print $4}'@lt@10000@throttle@No space @@@df -i .|awk 'NR==2 {print $4}'@lt@1000@throttle@No space (inodes) The first line causes the server to be throttled if the free space drops below 10000 units (using whatever units df uses), and restarted again when free space increases above the threshold. The second line does the same for inodes. The next three lines act as a group and should appear in the following order. It is easier to explain them, however, if they are described from the last up. !load!load hiload!loadavg!lt!5!go! :hiload:+ load:loadavg:gt:8:throttle:loadav /load/+/loadavg/ge/6/pause/loadav The final line causes the server to be paused if innwatch is in the ``run'' state and the load average rises to, or above, six. The state is set to ``load'' when this happens. The previous line causes the server to be throttled when innwatch is in the ``run'' or ``load'' state, and the load average rises above eight. The state is set to ``hiload'' when this happens. Note that innwatch can switch the server from ``paused'' to ``throttled'' if the load average rises from below six to between six and seven, and then to above eight. The first line causes the server to be sent a ``go'' command if innwatch is in the ``load'' or ``hiload'' state, and the load average drops below five. Note that all three lines assume a mythical command loadavg that is assumed to print the current load average as an integer. In more prac- tical circumstances, a pipe of uptime into awk is more likely to be useful. BUGS
This file must be tailored for each individual site, the sample supplied is truly no more than a sample. The file should be ordered so that the more common problems are tested first. The ``run'' state is not actually identified by the label with that three letter name, and using it will not work as expected. Using an ``unusual'' character for the delimiter such as ``('', ``*'', ``&'', ```'', ``''', and the like, is likely to lead to obscure and hard to locate bugs. HISTORY
Written by <kre@munnari.oz.au> for InterNetNews. This is revision 1.5, dated 1996/09/06. SEE ALSO
innd(8), ctlinnd(8), news.daily(8). INNWATCH.CTL(5)