AWK issue--> Help requested


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK issue--> Help requested
# 1  
Old 02-26-2007
Error AWK issue--> Help requested

Fairly new scripter so please bare with me if what I have done below is not according to standards.

Okay...heres what I am trying to do. I have a pattern that I need to search for in a directory. This gives me a list of files that includes a control file that contains totals of the line nos for each file.

I need to compare the line no totals in the control file to those of the actual file.

This is what I have written as of now::
Note: $1 = feb99
Code:
#!/bin/ksh

# Check if totals match with control file.
# Usage ./compresser.sh <pattern>

ls -ltr | grep "$1" | grep -v control | awk ' { print $9 } ' > tmp1
ttt =`ls -ltr | grep "$1" | grep ism_control | awk ' { print $9 } '`
echo "Control File=$ttt"

while read line
    do
        
    t1=`awk ' { FS = "," } ; { print $1 } ' "$line"`
    
    sumt1= `awk ' { FS = "," } ; {print $3} '`
    
    t2=`grep -i $t1 tmp1`
    
    sumt2=`wc -l $t2`
    
     if [ $t1 -eq $t2 ]; then
       continue
     else mailx -s "$t1 $t2 sums unmatched" abc@abc.com
       echo "Sum matching error!"
     exit 1
     fi
     
     done      < $ttt

exit 0

The control file looks like this:

Code:
$ cat ism_control_feb99.dat
CLM,070226,000000260057,0000000000000.00,0000000000000.00
DTL,070226,000000779444,0000340452084.72,0000071200080.15
EOB,070226,000000795479,0000000000000.00,0000000000000.00
HML,070226,000000106570,0000000000000.00,0000000000000.00
HSP,070226,000000037861,0000000000000.00,0000000000000.00
MED,070226,000000047404,0000000000000.00,0000000000000.00

tmp1 looks like this
Code:
$ more tmp1
ism_clmp_feb99.dat
ism_dtlp_feb99.dat
ism_eobp_feb99.dat
ism_hspp_feb99.dat
ism_hmlp_feb99.dat
ism_medp_feb99.dat

So basically what I am trying to do through the script is list all files that contain feb99 and put them in a file tmp1. Then based on pattern matches eg field1 CLM from ism_control_feb99.dat is used to search for ism_clmp_feb99.dat and field3 000000260057 from the control file is mathed with wc -l of actual file ie ism_clmp_feb99.dat and then send email.

Below is the error I am getting on executing script(Have already tried nawk/gawk):

Code:
Control File=ism_control_feb99.dat
line=CLM,070226,000000260057,0000000000000.00,0000000000000.00
awk: 0602-533 Cannot find or open file line.
 The source line number is 1.
t1=
./compresserv2.sh[15]: 000000779444:  not found.
sumt1=
t2=
sumt2=       0

HELP!
# 2  
Old 02-26-2007
Dude!!! I don't think I understood your problem fully..but here is what i tried...take a look..


t1=`echo "$line" | awk -F"," '{print $1}'`
sumt1= `echo "$line" | awk -F"," '{print $3}'`
sumt2=`grep -i $t1 tmp1 | wc -l`
now compare sumt1 & sumt2 & then do whatever you want do..
# 3  
Old 02-26-2007
Completely untested:

Code:
#!/bin/ksh

# Check if totals match with control file.
# Usage ./compresser.sh <pattern>

ttt="ism_control_$1.dat"
echo "Control File=$ttt"

OIFS=$IFS
IFS=,

while read t1 junk sumt1 more_junk; do
    typeset -l t2
    t2="ism_${t1}_${1}.dat"    
    sumt2=$(wc -l $t2)
    
     if [[ $sumt1 -eq $sumt2 ]]; then
       continue
     else mailx -s "$t1 $t2 sums unmatched" abc@abc.com
       echo "Sum matching error!"
     exit 1
     fi
     
done < $ttt

IFS=$OIFS

exit 0

# 4  
Old 02-27-2007
Success

Thanks reborg and Gop...i did not completely understand reborgs script--what is typset?
So I continued to work on the one from gop. This is what worked for me:

Code:
#!/bin/ksh
# Check if line sums match with control file.
# Usage ./compresser.sh <pattern>

ls -ltr | grep "$1" | grep -v control | awk ' { print $9 } ' > tmp1
ttt=`ls -ltr | grep "$1" | grep control | awk ' { print $9 } '`
#echo "Control File=$ttt"
echo "Comparing sums..."

while read line
    do    
        t1=`echo "$line" | awk -F"," '{print $1}'`
        sumt1=`echo "$line" | awk -F"," '{print $3}'`
        t2=`grep -i "gnc$t1" tmp1`
        sumt2=`wc -l $t2 | awk ' { print $1 } '`
           if [ $sumt1 -eq $sumt2 ]; then
           continue
           else mailx -s "$t1 $t2 sums unmatched" abc@abc.com
           echo "Sum matching error for $t1!"
           exit 1
           fi
     done < $ttt

Again...thanks a lot people...u guys are wonderful!

Last edited by alfredo123; 02-27-2007 at 04:17 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. IP Networking

The requested URL was rejected. Please consult with your administrator

Ggod evening. I need your help please, in a Production system there is a process that download a xls file from an URL which is IMF(International Monetary Fund) and afterwards to be loaded into a databse table. When testing conectivity from a unix server to IMF seems to work but when editing it... (9 Replies)
Discussion started by: alexcol
9 Replies

2. Shell Programming and Scripting

SQL Script HELP Requested.

Hello ALL , i am requesting help on for this script i am preparing to get the result of a query in a excel sheet : current Error: Script : NO Excel file created. requesting to know where i am going wrong. #!/bin/ksh... (2 Replies)
Discussion started by: anirudhkashikar
2 Replies

3. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

4. Forum Support Area for Unregistered Users & Account Problems

Sign in issues -- additional info as requested

User name: Michael Mullig <removed email addresses> (1 Reply)
Discussion started by: Mike Mullig
1 Replies

5. Shell Programming and Scripting

Help on sed requested

Hi I have a problem to resolve, I think sed is the best option, and I am not successful yet. Have a UNIX file which has records as of the 2 character state codes like NY NJ PA DE From the file I need to create this as a variable in the same script or another file -... (7 Replies)
Discussion started by: snair2010
7 Replies

6. Shell Programming and Scripting

Newbie bash scripting help requested

Hi, I'm very new to bash scripting and Linux in general. I'm running Ubuntu Server 10.04 and trying to write a bash script to launch a program. In doing so, I've come across a couple of things that I obviously don't understand. Here is a short script that exemplifies those things: ... (9 Replies)
Discussion started by: Carson Dyle
9 Replies

7. Shell Programming and Scripting

Help requested for a script with sed

Hello Folks, I would very much appreciate if I could get help/suggestions on a particular sed usage. I have to write a script to take version info from a version file, compute the image name, print error if the image does not exist. The version file looks like below: " # # version.cfg #... (3 Replies)
Discussion started by: fatimap
3 Replies

8. UNIX for Advanced & Expert Users

assistance requested (sed related)

I gotta write a command to change the accounts in /etc/passwd that use a shell other than the bash to bash shell. those accounts that dont use a shell shouldnt get modified. assuming all the shell programs end in sh and other programs dont. and the result should go into /etc/passwd.rev any hint? (4 Replies)
Discussion started by: metalwarrior
4 Replies

9. Solaris

Your Opinion requested

Ladies/Gentlemen, I am looking for a web-based tool to keep track of my Sun inventory. The following list of fields are fields I would like to store: Root Passwd (needs to be secure) / Hostid / Console Port / IP Address / Platform / Application / Hostname . . . you get the point. Do any of... (4 Replies)
Discussion started by: pc9456
4 Replies

10. Email Antispam Techniques and Email Filtering

help requested: procmail receipes

Hello all. I want some help procmail receipe. I tried to get some mails' sender and receiptient. Then tried to send them a bash script. But it didnot work. I try a lot of variation of the below receipe. Could anyone can help what is wrong on my receipe? Or if the recepie is correct what can be... (0 Replies)
Discussion started by: kedi
0 Replies
Login or Register to Ask a Question