Help me in awk with getline...Am new to the awk please..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help me in awk with getline...Am new to the awk please..
# 1  
Old 06-22-2011
CPU & Memory Help me in awk with getline...Am new to the awk please..

Hello,

Am using a script that will give output like below.
Code:
emp = WH.3060                            salary  = 5
emp = WH.7235                            salary  = 5
emp = WH.6345                            salary  = 6
emp = WH.0234                            salary  = 5
emp = WH.5644                            salary  = 8
emp = WH.1009                            salary  = 9
emp = WH.9887                            salary  = 5
emp = WH.6783                            salary  = 7
emp = WH.8764                            salary  = 5
emp = WH.3562                            salary  = 5

My need:

i need the whole row where salary greater then 5.

Expected output:
Code:
emp = WH.6345                            salary  = 6
emp = WH.5644                            salary  = 8
emp = WH.1009                            salary  = 9
emp = WH.6783                            salary  = 7


Can anyone give me awk command for this please.........Is there any other command for this?

Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 06-22-2011 at 05:06 PM.. Reason: code tags, please!
# 2  
Old 06-22-2011
Code:
nawk '$NF>5' myFile

# 3  
Old 06-22-2011
Superb... can you please explain me whats happening with $NF? awk will extract whole column right? who it works with line by line?
# 4  
Old 06-22-2011
Quote:
Originally Posted by prince1987
Superb... can you please explain me whats happening with $NF? awk will extract whole column right? who it works with line by line?
'man nawk' yields:
Code:
       NF
            The number of fields in the current record, with a limit of 99.
            Inside a BEGIN action, the NF special variable is undefined unless
            a getline function without a Variable parameter has been issued
            previously. Inside an END action, the NF special variable retains
            the value it had for the last record read, unless a subsequent,

            redirected, getline function without a Variable parameter is
            issued prior to entering the END action.

therefore, $NF yields the value of the last field of the record/line.
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

Getline not working in awk

hi, i am trying to parse a file in awk to generate a output to be written in a file depeding upon some condition. below is the code Content of file1 919873741577,9131638459976206,20130715150109,S,919811000214,2A65,405899136999995... (10 Replies)
Discussion started by: siramitsharma
10 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

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

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

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

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

10. Shell Programming and Scripting

awk:Problem with getline

$ echo |awk ' BEGIN {"date" | getline current_time;close("date");print "Report printed on " current_time}' Report printed on Thu May 11 14:57:29 METDST 2006 This example works fine but how can i print all the output when is longer... (3 Replies)
Discussion started by: Klashxx
3 Replies
Login or Register to Ask a Question