Awk scripting issue


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Awk scripting issue
# 1  
Old 01-18-2005
Awk scripting issue

Ok, after pulling my hair out on this one, i need to ask for some help

I have a file called "final" that looks like the following (this is a section of a bigger file)

Code:
18-5-252906,180105,00041.00,42070461139120,AUTH CODE:630911,000,101
18-5-255398,170105,01594.00,42110524389101,AUTH CODE:066811,003,101
19-5-239531,170105,00628.00,42124415729001,AUTH CODE:636236,003,101
15-5-268103,170105,00395.13,42123345209101,AUTH CODE:083378,003,101
18-5-255630,170105,02108.00,42135735559001,AUTH CODE:3698  ,003,101
20-5-258607,180105,00015.88,42121026959101,AUTH CODE:014001,000,101
18-5-255906,180105,00040.00,42070461139100,AUTH CODE:630911,000,101
20-5-258611,180105,00040.25, 4205843099910,AUTH CODE:082704,000,101
20-5-258751,180105,00020.00,42103493309100,AUTH CODE:6850  ,001,101


----------------
My script looks like this


Code:
awk 'BEGIN { FS="," } { if ( $5$6 ~ /AUTH CODE.*(000|001|100)/ ) { print $0 } }' final > finaltemp
awk -F',' ' length(sprintf("%.0f",0+$4))!=14{print > "exceptions2";next} {print} ' finaltemp > WSECTRAD
awk 'BEGIN { FS="," } { if ( $6 ~ /055|002|003/ ) { print $0 } }' final > exceptions3
awk 'BEGIN { FS="," } { if ( $5 ~ /REFUND|REFERRAL/ ) { print $0 } }' final > exceptions1


the script process
------------------

As you can see from my script above, I run some awk commands on this file called "final" to extract the data i need.. there are 7 columns in total in the file seperated by a comma.

1) My first line of awk looks at the 5th and 6th column for the words AUTH CODE and a three letter code 000, 100, or 001 respectivly and then extracts to a file called finaltemp

2) The next line, checks to see if the 4th column is indeed 14 characters, if not then chucks it to an exceptions file , it then creates a file called WSECTRAD with all records that ok

3) The next awk extracts column 6 values of 055, 002 and 003 to another exceptions file

4) And finally another awk looking at column 5 for some keywords, again throwing them out to an exceptions file



Now that all seesm to work great, except strangely on a couple of occasions where a single 003 (in the 6th column) seems to make its way into the WSECTRAD file AND the exceptions file ?!? ....I can obviously understand why it goes to exceptions, because a 003 is an exception.....but why does this one rogue entry end up in WSECTRAD ??

here is the culprit record for today...see below



18-5-255398,170105,01594.00,42110524389101,AUTH CODE:066811,003,102




As you can see from the section of the "final" file at the top,(its the second one from the top) it is not the only 003 at all, infact there are loads of these throughout the file, and unless I am going blind, I cant see the difference between this record and any of the other 003's (as far as the awk scripts are concerned anyway)

Can anybody spot any reasoning why this one record is the only 003 to hit the WSECTRAD file ??? (as mentioned before, A copy does also go to the correct exceptions file aswell)


Any help on this would be greatly appreciated
# 2  
Old 01-18-2005
I changed

$5$6 ~ /AUTH CODE.*(000|001|100)/

to

$5$6 ~ /AUTH CODE.*(000|001|100)$/

(notice the dollar to explicity define the end of the 6th field) in the first awk and that seems to fix it for me.

Cheers
ZB
# 3  
Old 01-18-2005
ill give it a go, thankyou
# 4  
Old 01-18-2005
The reason it was bringing in the record with "003" in it was because the end of the 5th field for that record ended in "1". When you concatenate the two fields with $5$6, you end up with "1003" at the end of $5$6 which matches the rule you defined in the first awk. Therefore, you need the "$" at the end of the regex to tell it that the (000|001|100) is anchored at the very end of the fields in the match.

Cheers
ZB
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Scripting issue

I am having a problem. which I have described below>> I have to run a script with the format : <File_name><Start_date><End_date> abcd.sh 19-JAN-2015 01-May-2014 problem is I need to compare these two dates and throw an error as start date must be less than or equal to end date. But... (13 Replies)
Discussion started by: Chandan_Bose
13 Replies

2. Shell Programming and Scripting

Scripting Issue with Variables from awk

Greetings all, Disclaimer: I'm a novice and always welcome best practices as I'm learning. File example: 100,1.1.1.1,1.1.1.2,10.10.10.1,172.16.1.10,172.16.1.20 101,1.1.2.1,1.1.2.2,10.10.20.1,172.16.2.10,172.16.2.20 102,1.1.3.1,1.1.3.2,10.10.30.1,172.16.3.10,172.16.3.20 ...and so on ... (3 Replies)
Discussion started by: sjrupp
3 Replies

3. Shell Programming and Scripting

Scripting Issue

needing this script to shut down 1 IceS and start up another, close the 2nd one after 12 seconds and then reboot. here is what i have so far #!/bin/bash ShutDown() { echo "Shutdown in progress." wall <<ENDOFWALL CI Shutdown has been intiated!!!! Shutdown will occur in 30 seconds...... (1 Reply)
Discussion started by: Zaine
1 Replies

4. Shell Programming and Scripting

Scripting Issue

I am having an issue with a script that I created today, my first attempt at this, and was wondering if anyone can give me insight to what changes need to be made. Below is a copy of the script that I have written. WEe are trying to monitor whether or not a services is running. I do have a cron... (1 Reply)
Discussion started by: lsudubee
1 Replies

5. Shell Programming and Scripting

awk scripting issue

hi guys, I am quite a newbie to Linux.I have an issue.Please help me; I have to create a script that runs "ls -la" inside a directory Bong and then I need to run the command through awk and have the output as follows: Filename: abc.txt Owner: test1 Group: test2 Permissions:... (1 Reply)
Discussion started by: mahesh_raghu
1 Replies

6. Shell Programming and Scripting

Scripting issue

Hello, I have an ASCII file (many files of the same format, but different dates and numbers) in the format like below: 2008.01.02,08:00,1.46520,1.46520,1.46410,1.46440,70 2008.01.02,08:05,1.46450,1.46560,1.46440,1.46540,79 2008.01.02,08:10,1.46530,1.46540,1.46490,1.46500,46... (8 Replies)
Discussion started by: chief2000
8 Replies

7. Shell Programming and Scripting

scripting issue

Hello, Guys I am having a sql script file which contains some sql statements including inserting values, One column is of the data type date. Now i am having a KSH script for inserting values via this script into the database. The problem I am facing that when I am inserting value in the... (1 Reply)
Discussion started by: mraghunandanan
1 Replies

8. Shell Programming and Scripting

IP-Scripting Issue

Hi Guys, I am quite new to Shell Scripting... I need ur help.. This is very urgent. The thing is like, I need to match a IP address (ex 192.168.200.56) i.e, xxx.xxx.xxx.xx inside a KSH script,but if we enter in different format other than the specified format (ex jjj.ksj., 1.0...), it should... (3 Replies)
Discussion started by: mraghunandanan
3 Replies

9. Shell Programming and Scripting

Scripting issue..

Hi guys... I am a newbie to scripting... I have a small requirement... I dont whether u r clear with my requirement... But plz try to help me... Like, tell me some kind of scripts that can help me in retreiving the data from the datasets. Regards, Mahesh... (1 Reply)
Discussion started by: mraghunandanan
1 Replies

10. Shell Programming and Scripting

scripting issue

folks; i'm trying to write a shell script to do the following: 1. i have a file with 39 fields, i'm trying to add 10 more fields with (!) as a field separator. with the following requirement: if field number 20 has a value, then field number 40 will show as (!M!), and if the field number 20 does... (2 Replies)
Discussion started by: moe2266
2 Replies
Login or Register to Ask a Question