Sponsored Content
Top Forums Shell Programming and Scripting awk find a string, print the line 2 lines below it Post 302465165 by Scrutinizer on Thursday 21st of October 2010 07:05:04 PM
Old 10-21-2010
First a little shortening Smilie :
Code:
awk '$1=="hostgroup_name" && $2==hgn {getline;getline;print}' hgn="chat-qa" infile

or you can use sed:
Code:
hgn="chat-qa"; sed -n "/hostgroup_name.*$hgn/{n;n;p}" infile

To find members without the double getline:
Code:
awk '$1=="hostgroup_name" && $2==hgn{p=1} $1=="members" && p{p=0;print}' hgn="chat-qa" infile


Last edited by Scrutinizer; 10-21-2010 at 08:14 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl : Find a string and Print full line

Hi Need a perl script to read lines in a file, scan for a string named "APPLE" and write to different file the only lines containing the matched string. (5 Replies)
Discussion started by: PrasannaKS
5 Replies

2. Shell Programming and Scripting

awk to print lines based on string match on another line and condition

Hi folks, I have a text file that I need to parse, and I cant figure it out. The source is a report breaking down softwares from various companies with some basic info about them (see source snippet below). Ultimately what I want is an excel sheet with only Adobe and Microsoft software name and... (5 Replies)
Discussion started by: rowie718
5 Replies

3. Shell Programming and Scripting

Print lines after the search string until blank line is found

All I want is to look for the pattern in the file...If I found it at # places... I want print lines after those pattern(line) until I find a blank line. Log EXAMPLE : MT:Exception caught The following Numbers were affected: 1234 2345 2346 Error java.lang.InternalError:... (3 Replies)
Discussion started by: prash184u
3 Replies

4. Shell Programming and Scripting

Find a string using grep & print the line above or below that.

Hi All, Please tell me how can I Find a string using grep & print the line above or below that in solaris? Please share as I am unable to use grep -A or grep -B as it is not working on Solaris. (10 Replies)
Discussion started by: Zaib
10 Replies

5. Shell Programming and Scripting

Awk - find string, search lines below string for other strings

What's the easiest way to search a file for a specific string and then look for other instances after that? I want to search for all Virtual Hosts and print out the Server Name and Document Root (if it has that info), while discarding the rest of the info. Basically my file looks like this: ...... (6 Replies)
Discussion started by: Mbohmer
6 Replies

6. Shell Programming and Scripting

Search string and print the above line and below lines?.

if the first string matches then print the previous line and current line and also print the following lines if the other string search matches. Input ------ TranTime 2012 10 12 The Record starts here Accountnumber: 4632473431274 TxnCode 323 TranID 329473242834 ccsdkcnsdncskd... (7 Replies)
Discussion started by: laknar
7 Replies

7. Shell Programming and Scripting

String search and print next all lines in one line until blank line

Dear all I want to search special string in file and then print next all line in one line until blank lines come. Help me plz for same. My input file and desire op file is as under. i/p file: A1/EXT "BSCABD1_21233G1" 757 130823 1157 RADIO X-CEIVER ADMINISTRATION BTS EXTERNAL FAULT ... (7 Replies)
Discussion started by: jaydeep_sadaria
7 Replies

8. Shell Programming and Scripting

awk find and print next string

Can I do this in one awk session. Solution I have is poor. I want to return the number after PID. echo "Start: 12345 is used by PID:11111 username" | awk -F: '{print $3}' | awk '{print $1}' (6 Replies)
Discussion started by: u20sr
6 Replies

9. UNIX for Advanced & Expert Users

How to find a string in a line in UNIX file and delete that line and previous 3 lines ?

Hi , i have a file with data as below.This is same file. But actual file contains to many rows. i want to search for a string "Field 039 00" and delete that line and previous 3 lines in that file.. Can some body suggested me how can i do using either sed or awk command ? Field 004... (7 Replies)
Discussion started by: vadlamudy
7 Replies

10. Shell Programming and Scripting

Find a string and print all lines upto another string

Ok I would like to do the following file test contains the following lines. between the lines ABC there may be any amount of lines up to the next ABC entry. I want to grep for the filename.txt entry and print the lines in between (and including that line) up to and including the last line... (3 Replies)
Discussion started by: revaroo
3 Replies
nagios3stats(8) 						      nagios							   nagios3stats(8)

NAME
nagios3stats - report statistics information from the nagios system SYNOPSIS
nagios3stats [-hVL] [-c config] [-m] [-d] DESCRIPTION
nagios3stats Is a program designed to provide information on the running nagios system. It can provide a brief summary of information, or it can be used to export specific information about the nagios system into an MRTG-compatible format. For more information please consult the nagios online documentation available at http://www.nagios.org or the documentation available with your nagios server's web page. OPTIONS
-c|--config=FILE The main configuration file. On debian systems this defaults to /etc/nagios3/nagios.cfg -m|--mrtg Print output in MRTG-compatible format. For more details run nagios3stats with --help -d|--data=VARS Comma-seperated list of variables to output in MRTG format. For more details run nagios3stats with --help. -h|--help A helpful usage message -V|--version Print version information -L|--license Print license details FILES
/etc/nagios3 Default configuration directory for nagios3 AUTHOR
nagios3 is written and maintained by Ethan Galstad <nagios@nagios.org>. This manual page was written by sean finney <seanius@debian.org> for the Debian GNU/Linux operating system (but it may be freely used, modified, and redistributed by others). sean finney February 2006 nagios3stats(8)
All times are GMT -4. The time now is 11:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy