awk getline question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk getline question
# 1  
Old 11-30-2012
awk getline question

hi experts

i like to know how to print more line using getline command using awk. with below command i can only see one line (line no:1)

however i do have more line as shown below line no:2,line no:3,line no:4 and so forth. how do i get those to show up using the below command. I tried several option but no luck.

Code:
 
# awk '/Hardware/ { print; getline; print; } ' infile
Hardware
Line no: 1
Line no:2
Line no:3
Line no:4

thanks for any help!
# 2  
Old 11-30-2012
Code:
awk '/START/,/END/' file

i.e.
awk '/Hardware/,/^$/' file

The example would print from Hardware to the next empty line. Not sure if this is what you're looking for.
This User Gave Thanks to in2nix4life For This Post:
# 3  
Old 11-30-2012
thanks it work! but do add more line which i dont need, do you know how can i filter those? or refine it littel better?

i been looking to do this for few days and you solve my problem atleast i am on right pathSmilie
# 4  
Old 11-30-2012
Show the input you have and the output you want, please.
# 5  
Old 11-30-2012
hi,

output is very large so i will paste first line of the unwanted text from the working output. keep in mind this unwanted output shows up after my hardware lines (which i do like to see) i dont want to see anything related to rpc-reply and below from the same output. this output gets attach to the same command you provided earlier but at the very bottom. so i think there must be a way to filter out this unwanted text.


Code:
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/XXX.XXX/junos">


Last edited by Scott; 11-30-2012 at 06:06 PM.. Reason: Code tags
# 6  
Old 11-30-2012
You don't need to post the complete file, of course, but I need more than just the first line. Post enough that there's some data you do want, and some data you don't want. How else can we test if our programs will actually work for you?

Also post matching output for that input. When the results we get match what you want, that's how we can tell if our programs are doing what you want.
# 7  
Old 11-30-2012
OK Corona,

here you go, so i want upto fan try 2 , nothing after that like no rpc-reply line etc..

Code:
Fan Tray 1                                               FFANTRAY-M320-S
Fan Tray 2                                               RFANTRAY-M320-S

<rpc-reply xmlns:junos="http://xml.juniper.net/junos/10.4X29/junos">
    <chassis-inventory xmlns="http://xml.juniper.net/junos/10.4X29/junos-chassis">
        <chassis junos:style="inventory">
            <name>Chassis</name>

Thanks in advance!

Last edited by Scott; 11-30-2012 at 06:07 PM.. Reason: Code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk with if, getline, and another if

Howdy Folks, It seems like it is always awk that confuses the heck out of me and I even have books and examples. I have this line: awk '{if (/clientIP/)(SRV = $NF); if ($2 ~ /BUNDLE-GIM/) getline; if ($2 ~ /r100595/) {print SRV,"BUNDLE-GIM",$2}}' post.txt to parse this text: <api... (4 Replies)
Discussion started by: port43
4 Replies

2. Shell Programming and Scripting

awk getline

Hi, I have an awk script with the following function in it . function cmd( c ) { while( ( c | getline foo) > 0 ){ return foo ; close( c ); } } c =... (4 Replies)
Discussion started by: MetaMan
4 Replies

3. Shell Programming and Scripting

awk getline function help

Hello All , I have to split a file as well as keep the header in all the splitted files. For this I am using the getline function of awk to keep the header however the catch is header is of 4 lines and I have to hold all the 4 lines by getline function(or is there any other option ???) into a... (5 Replies)
Discussion started by: Pratik4891
5 Replies

4. Shell Programming and Scripting

awk getline t file

I want to import a textfile with getline into var t which has several lines. How do import all lines, since it only imports the last line: while < ((getline t "textfile") > 0) (7 Replies)
Discussion started by: sdf
7 Replies

5. Shell Programming and Scripting

Some Awk Getline help?

Greetings, I have about 3000 files that I want to search. The first column in all of these 3000 files has a unique serial number on each line. The subsequent columns have lots of data. I have another masterfile with three columns to help me find all the data I need in a moments notice: col 1... (15 Replies)
Discussion started by: jeeplou
15 Replies

6. Shell Programming and Scripting

awk getline question

Hi there, I have an ifconfig output and i want to write a script that determines whether there is a line "groupname ipmp" on a particular interface here is my example ifconfig -a output lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1 inet 127.0.0.1... (2 Replies)
Discussion started by: rethink
2 Replies

7. Shell Programming and Scripting

Using getline in awk

I am using awk and want to use getline from a file like below getline x < file However file consists of two columns and I only want to store $2 Any way I can do this? ---------- Post updated at 06:54 AM ---------- Previous update was at 06:45 AM ---------- Done something like this.... (1 Reply)
Discussion started by: kristinu
1 Replies

8. Shell Programming and Scripting

awk getline

How do you make the getline function return to the original line? The example below should make it clear where I am currently going wrong. Thanks AWK SCRIPT: ------------- awk -F '-' '{ tmpLine = "EMPTY" print "CURRENT LINE :"$0 getline tmpLine print "NEXT LINE :"tmpLine }'... (1 Reply)
Discussion started by: garethsays
1 Replies

9. Shell Programming and Scripting

awk and system getline

Hello, Need some help here. I have this script (test.sh): #!/bin/sh var=$1 (( var = 2 * var )) echo $var Now I want to call this script from awk with one argument and then capture the result in a variable, something like: echo 40 | awk ' { x = $1; "test.sh " x | getline y; print y }... (1 Reply)
Discussion started by: fbg
1 Replies

10. Shell Programming and Scripting

awk getline help maybe?

hello collegues, I am attempting to use awk to search file1 (serverlist.csv) from each row with file2 (supported.txt). If the is no entry exists in serverlist then output to a file called notsupp.out if there is an entry output to supp.out I can do this with basic shell scripting however... (0 Replies)
Discussion started by: chlawren
0 Replies
Login or Register to Ask a Question