Please help!!!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Please help!!!
# 57  
Old 07-21-2006
Quote:
Originally Posted by mhssatya
Reborg,

The server is up and running. Here is the output. It still didn't create 2nd file.

+ dev=/biddf/ab6498/dev/ctl
+ cd /biddf/ab6498/dev/ctl
+ echo /biddf/ab6498/dev/ctl
/biddf/ab6498/dev/ctl
+ + date +%Y%m%d
files=CARE01_DLY_???_20060721
+ echo CARE01_DLY_AUS_20060721 CARE01_DLY_MKT_20060721
CARE01_DLY_AUS_20060721 CARE01_DLY_MKT_20060721
+ awk {data[FNR] = $0; out=FILENAME "_new"; file[FNR]=out;} END { if (
FNR - 2 == $1) { for ( i=2 ; i < NR; i++ ) { print data[i] > file[i]}
close(file[i])}else { print "error"} } CARE01_DLY_AUS_20060721
CARE01_DLY_MKT_20060721
awk: A print or getline function must have a file name.
The input line number is 5. The file is CARE01_DLY_MKT_20060721.
The source line number is 1.
looks like you missed a couple of changes...the ones in bold should be NR not FNR.
# 58  
Old 07-21-2006
Reborg,

You are great man. It's working. But only thing is that i had two files like this:

CARE01_DLY_MKT_20060721:

RUN
1
1
2

and another file CARE01_DLY_AUS_20060721

RUN
1
1
42

So in the 2nd file CARE01_DLY_AUS_20060721 the record count doesn't match the data rows. Instead of thruoghing error it created two files like
CARE01_DLY_AUS_20060721_new. It shuold through error even if one file has wrong count. But it created 2 files though.

CARE01_DLY_AUS_20060721_new
CARE01_DLY_MKT_20060721 _new

So what should we change?

I thank you very much for helping me to solve this problem.

Y
# 59  
Old 07-22-2006
Changed a good bit, so I'll post a whole script again, however only the awk part has changed, there are a few changes, so please double check you've got them all if you have problems. I have tested this and it does work.

Code:
#! /usr/bin/ksh
dat=/biddf/ab6498/dev/ctl
cd $dat
files=CARE01_DLY_???_`date '+%Y%m%d'`


awk '{data[NR] = $0; out=FILENAME "new"; file[NR]=out;} END { if ( FNR - 2 != $1) { print "error" ; exit 1 } if ( ARGIND == --ARGC ){ for ( i=2 ; i < NR; i++ ) { print data[i] > file[i] }  close(file[i])}}' $files

# 60  
Old 07-22-2006
Reborg,

I will try in couple of hours. I really thank you for your great help man. It's all most late night and I will be away from my computer for some time. I will revert back once i run your wonderful script.
# 61  
Old 07-22-2006
Reborg,

I was just wondering if we can make the same script work when we mass the file name as parameter. For eg if we say awksatya.ksh CARE01_DLY the script should check for files for todays date and do the same processing. is this possible with the same script. Kindly suggest.
# 62  
Old 07-22-2006
Yes, just replace

files=CARE01_DLY_???_`date '+%Y%m%d'`

with

files=${1}_???_`date '+%Y%m%d'`

I am now going to close this thread to prevent it from being posted to again with new questions, as anyone posting to it would be unlikely to find anyone willing to read 62 posts so they could understand the question being asked.
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question