Sponsored Content
Top Forums Shell Programming and Scripting awk - use fields from subsequent lines Post 302576719 by agama on Friday 25th of November 2011 10:11:34 PM
Old 11-25-2011
Try this:
Code:
awk '
    /^INSTANCE/ {
        if( instance )
            printf( "%s %s %s\n", instance, tags[0], tags[1] ? tags[1] : "NULL" );
        instance = $2;
        tidx = 0;
        delete tags;
        next;
    }
    /^TAG / {
        tags[tidx++] = $5;
        next;
    }
    END {
        printf( "%s %s %s\n", instance, tags[0], tags[1] ? tags[1] : "NULL" );
    }
' input-file

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

replace only 1st word of a line if it comes in the subsequent lines at same postion.

I have a file like this.. Maharastra Mumbai worli Maharastra Mumbai navy maharatra Pune Maharastra Nagpur Karnataka Bangalore Karnataka Mysore Karnataka Mangalore Punjab Amritsar punjab Jalandar my expected outcome should be like this Maharastra Mumbai worli ---------- ... (9 Replies)
Discussion started by: geeko
9 Replies

2. Shell Programming and Scripting

How to extract a substring and append to subsequent lines

Hi all,I am really new to Shell Scripting.I have the following doubt. Let us assume the one sample file which contains the below data HEADERCARMENTRACIE1555090414 PERIOD0905090501090531 DETAIL0645693037023073836 GROUNDAV 090501 01 GROUNDAV 090502 01 TRIP 0091282542 0905084101... (5 Replies)
Discussion started by: jaligamasriniva
5 Replies

3. Shell Programming and Scripting

How to search for keywords in subsequent lines

Hi all, I am looking for a coomand to search for the keywords in susequenct lines. Keyword1 in a line and Keyword2 in the very next line. Once i found the combination ineed to print the lines with patterns and the line above and one below. I am giving an example here: Keywords are :ERROR and... (12 Replies)
Discussion started by: rdhanek
12 Replies

4. Shell Programming and Scripting

search for keyword in subsequent lines and delete the second line

I have my data something like this I need to search for the keyword yyyy in the susequent lines and if it is present, delete the second line with keyword. In other words, if a keywords is found in two subsequent lines delete the second line. input data: aaaa bbbbb cccc dddd xxxx... (4 Replies)
Discussion started by: rdhanek
4 Replies

5. Shell Programming and Scripting

Grep and fetch subsequent lines also

Hi, I need to grep a pattern and fetch subsequent lines till end of the data-set. E.g., i have a file like: AA 1111 23 34 BB 45 56 78 CC 22 44 AA 2222 78 34 56 BB 22 56 67 68 23 CC 56 78 DD 33 55 77 AA 3333 46 BB 58 79 In above file i have 3-data sets where each set starts with... (6 Replies)
Discussion started by: prvnrk
6 Replies

6. Shell Programming and Scripting

Find pattern, and then last field from subsequent lines

I've got a log file, of the format Name: network1 Dropped packets: 15618 Dropped packets for IPv6: 27 Dropped packets: 74 Dropped packets for IPv6: 0 Failed RADIUS Authentication procedures: 0 Failed RADIUS Accounting procedures: 0 Name: network2 Dropped packets: 1117 ... (18 Replies)
Discussion started by: Yorkie99
18 Replies

7. Shell Programming and Scripting

awk text record - prepend first field to all subsequent fields

Hello everyone, I've suddenly gotten very interested in sed and awk (and enjoying it quite a bit too) because of a large conversion project that we're working on. I'm currently stuck with a very inefficient process for processing text blocks. I'm sure someone here should be able to easily point out... (2 Replies)
Discussion started by: jameswatson3
2 Replies

8. Shell Programming and Scripting

AWK swapping fields on different lines

Hi All, Sorry if this question has been posted elsewhere, but I'm hoping someone can help me! Bit of an AWK newbie here, but I'm learning (slowly!) I'm trying to cobble a script together that will save me time (is there any other kind?), to swap two fields (one containing whitespace), with... (5 Replies)
Discussion started by: Bravestarr
5 Replies

9. UNIX for Advanced & Expert Users

Need command for grepping pattern lines with subsequent lines

Hi, I have a requirement like, I have a list of pattens in a file say pattern.txt, PHC111 PHC113 and in another file called master.lst i have entries like, PHC111 a b PHC112 a PHC113 b c PHC114 d e (5 Replies)
Discussion started by: rbalaj16
5 Replies

10. Shell Programming and Scripting

awk to combine lines if fields match in lines

In the awk below, what I am attempting to do is check each line in the tab-delimeted input, which has ~20 lines in it, for a keyword SVTYPE=Fusion. If the keyword is found I am splitting $3 using the . (dot) and reading the portion before and after the dot in an array a. If it does have that... (12 Replies)
Discussion started by: cmccabe
12 Replies
LINTIAN-INFO(1) 					User Contributed Perl Documentation					   LINTIAN-INFO(1)

NAME
       lintian-info - give detailed information about Lintian's error tags

SYNOPSIS
       lintian-info [log-file...]

       lintian-info --tags tag ...

DESCRIPTION
       The lintian-info command parses the output of the lintian command and gives verbose information about the listed Lintian error tags, parses
       a Lintian override file and gives verbose information about the tags included, or (if given the -t or --tags option) explains a given tag
       or tags.

       If no log-file is specified on the command line, this command expects its input on stdin. Thus, the output of lintian can either be piped
       through lintian-info or a log file produced by lintian can be processed with this command.  (Note, though, that the lintian command has a
       command line option -i to display the same results as lintian-info, so you will not normally need to pipe the output of lintian into this
       command.)

OPTIONS
       -a, --annotate
	   Read from standard input or any files specified on the command line and search the input for lines formatted like Lintian override
	   entries.  For each one that was found, display verbose information about that tag.

       -h, --help
	   Display usage information and exit.

       --profile prof
	   Use the severities from the vendor profile prof when displaying tags.  If the profile name does not contain a slash, the default
	   profile for than vendor is chosen.

	   If not specified, lintian-info loads the best profile for the current vendor.

	   Please Refer to the Lintian User Manual for the full documentation of profiles.

       -t, --tags
	   Rather than treating them as log file names, treat any command-line options as tag names and display the descriptions of each tag.

EXIT STATUS
       If -t or --tags was given and one or more of the tags specified were unknown, this command returns the exit code 1.  Otherwise, it always
       returns with exit code 0.

SEE ALSO
       lintian(1)

AUTHORS
       Niels Thykier <niels@thykier.net>

       Richard Braakman <dark@xs4all.nl>

       Christian Schwarz <schwarz@monet.m.isar.de>

perl v5.14.2							    2013-02-16							   LINTIAN-INFO(1)
All times are GMT -4. The time now is 06:05 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy