awk trik help needed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk trik help needed
# 1  
Old 02-11-2008
awk trik help needed

i have file like:
test.txt:
3:<:1
how to write awk program which will use field $2 as a condition and compare $1 with $3
somethink like:
awk -F":" '{if ($1 $2 $3) print}' test.txt #this not working Smilie
will work like:
awk -F":" '{if ($1 < $3) print}' test.txt

Regards
Peter

Last edited by pp56825; 02-11-2008 at 03:01 PM..
# 2  
Old 02-11-2008
Here's one way:
Note, my version of awk doesn't require the ":", if your's does add the double-quotes, awk -F":"
Code:
#!/usr/bin/ksh

cat test.txt | while read line
 do
        OP=`print $line | awk -F: '{ print $2 }' `
        case ${OP} in
                '<')
                         print $line | awk -F: '{ if ( $2 ~ /</ && $1 < $3 ) print ( $1,"less than",$3 ); else  print ( $1,"NOT less than",$3 )  }' 
                        ;;
                '>')
                         print $line | awk -F: '{ if ( $2 ~ />/ && $1 > $3 ) print ( $1,"greater than",$3 ); else  print ( $1,"NOT greater than",$3 ) }'
                        ;;
                '=')
                         print $line | awk -F: '{ if ( $2 ~ /=/ && $1 == $3 ) print ( $1,"equal to",$3 ); else  print ( $1,"NOT equal to",$3 ) }'
                        ;;
        esac
 done

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk help needed

Hi Everyone, i have following in my file 1 2 3 4 5 6 . . 100 and now i want the output as 1 4 7 ..........so on..............97 100 (10 Replies)
Discussion started by: zozoo
10 Replies

2. Shell Programming and Scripting

awk help needed

Hi Experts, I have a file (file 1) with several columns and I need to create 2 files based on the data of 20th column of file 1. Criteria 1 : If the 20th field of file1 is empty , copy the entire records to file 2. I am successfully able to do this with the following awk code : awk... (2 Replies)
Discussion started by: nua7
2 Replies

3. Shell Programming and Scripting

Awk Help needed

hi, I have input file woth records as shown below OCSMRC_OK,7057348733,+0.00,0,18/05/2010 23:42:19,BellMobility,302610000918553,0006056099,B30,686505,686505,OCS_MRC,+49.14,0,0 ,0,0, OCSPPKB_NOK,4163460120,+1.25,0,18/05/2010... (4 Replies)
Discussion started by: raghavendra.cse
4 Replies

4. UNIX for Dummies Questions & Answers

Awk help needed

I have a log file monitor script that checks through a log file for a string. I use awk to search the log file, starting at the last checked line, for the specified string and then output the count and the last row number checked. The part of the script that does all the work is here: set --... (6 Replies)
Discussion started by: mglenney
6 Replies

5. Shell Programming and Scripting

help needed in awk

Hi , i have a file a.txt like this: far near veryfar toonear typeset var1=veryfar to extract the text between two strings i use the following command : awk '/far/,$veryfar/' a.txt its not working can nyone tell pls whats wrong in it ? i doubt can we use variable in awk like this... (3 Replies)
Discussion started by: santosh1234
3 Replies

6. Shell Programming and Scripting

awk help needed

How do I alter this command so that it prints only the second comma delimited field from line number 3? Secondly, how do you redirect the output to a variable called TEST? Thanks (cat BATCH007.TXT | awk 'BEGIN { FS = "," } ; {print $2 }') (5 Replies)
Discussion started by: ddurden7
5 Replies

7. Shell Programming and Scripting

awk help needed

I am trying to write a script that will parse out the e-mail address of a person from the name of a file in a directory. Example: filename is: /home/myname/first.middle.last@email.com.xls I want to extract just the email address and mail the file to that address. I want to send the... (6 Replies)
Discussion started by: Drenhead
6 Replies

8. UNIX for Advanced & Expert Users

help needed on awk

Hi i have a file /services which has the following content. ff1 2201 f1 2202 In my program following logic is used. SVC=$NICKNAME PRT=$(awk '/'$SVC'/ { print substr($2,1,index($2,"/")-1); }'/services) where SVC will be ff1 and f1. when SVC is f1 the output of the... (2 Replies)
Discussion started by: blooddy
2 Replies

9. Shell Programming and Scripting

awk help needed.

Dear All, I want to compare column 3 and column 4 of files(File1 and File2) and want to get the matched records in one file and rejected records in another file.I have tried an awk script,but as Iam not good in it,I cant able to continue.Can anyone help me in this one. File 1... (0 Replies)
Discussion started by: cskumar
0 Replies

10. Shell Programming and Scripting

little help needed with my awk

i got a file (books.txt) 12 A 15 B And i want to output: Group allocation Group A: 12 books Group B: 15 books .. End List i know how to reverse the two fields by using awk {print $2,$1} books.txt Im having problems outputting what i wanted using awk so far i got: {print... (5 Replies)
Discussion started by: thewizard
5 Replies
Login or Register to Ask a Question