Script not working as desired


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script not working as desired
# 8  
Old 07-24-2006
Reborg,

It all most seems working. Except for the fact that in one file header is still there and in another file the count of records at the bottom is present. If both of them can be removed I think you made it all. Please see below for the debug script and output.

code with some numbers thrown out:

Quote:
+ 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_???_20060724
+ echo CARE01_DLY_AUS_20060724 CARE01_DLY_MKT_20060724
CARE01_DLY_AUS_20060724 CARE01_DLY_MKT_20060724
+ awk {data[NR] = $0; out=FILENAME "new"; file[NR]=out; records[out]=NR
} END { for ( r in records ) { sum += data[records[r]]; print sum }
print ARGC, NR, NR - (--ARGC * 2); if ( sum != NR - (ARGC * 2) ) {
print "error" } else {for ( i=2; i < NR; i++ ) { print data[i] > file[i]
} close(file[i])}} CARE01_DLY_AUS_20060724 CARE01_DLY_MKT_20060724
3
7
3 11 7
I wonder why thiscame in the output.
Ouput files:
Quote:
cat CARE01_DLY_AUS_20060724new
1
1
1
1
4
edwcrm@drwatson [213]/biddf/ab6498/dev/ctl $ cat
CARE01_DLY_MKT_20060724new
run
1
1
1
# 9  
Old 07-24-2006
Satya,

I am trying your script and getting the same output as you are getting. Let me know if you get to correct answer.
# 10  
Old 07-24-2006
Reborg,

Please help dude!!! Smilie
# 11  
Old 07-25-2006
Code:
awk 'FNR != 1 {

data[NR] = $0
out=FILENAME "new"
file[NR]=out
records[out]=NR

}



END {
        for ( r in records ) {
                sum += data[records[r]]
                print sum
        }

        print ARGC, NR, NR - (--ARGC * 2)
        if ( sum != NR - (ARGC * 2) ) {
                print "error"
        }
        else {
                for ( i in file ) {
                        if ( i != records[file[i]] ) {
                                print data[i] > file[i]
                        }
                }
                close(file[i])
        }
}
' $files

# 12  
Old 07-25-2006
Reborg : Simply Awesome!!!! Awesome Dude!!!

It's working perfect now. Great man. I started learning UNIX by this forum a lot.

Can you please explain the logic here if you have time. I am trying to understand by breaking it into pieces.
# 13  
Old 07-25-2006
Reborg:

Just a small question. If at the end of writing data rows into new files for each respective file if I want to append all the data rows into one single file what should i do? This should happen only if all the files have correct counts and records. I am checking where I can use the >> to append all the data rows and create one file for that day namely BARE01_DLY_20060725.

Kindly let me know.
# 14  
Old 07-25-2006
Assuming again you only want to do it if everything validates ok in the individual files:

Code:
awk -v complete_file=${1}_$(date+%Y%m%d) 'FNR != 1 {

data[NR] = $0
out=FILENAME "new"
file[NR]=out
records[out]=NR

}



END {
        for ( r in records ) {
                sum += data[records[r]]
        }

        if ( sum != NR - (ARGC * 2) ) {
                print "error"
        }
        else {
                for ( i in file ) {
                        if ( i != records[file[i]] ) {
                                print data[i] > file[i]
                                print data[i] > complete_file
                        }
                }
                close(file[i])
        }
        close(complete_file)
}
' $files


Last edited by reborg; 07-25-2006 at 09:57 PM.. Reason: update
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need comand or script for append text after searching for the desired string

Hi all, i have a generated report in unix in the following command like input.txt 47.85,10 0124,42.35,8 0125,3.5,2 the input file format is fixed I need the my output file with append text as below output.txt 0124 amount:42.35 0125 amount:3.5 0124 count : 8 0125... (34 Replies)
Discussion started by: hemanthsaikumar
34 Replies

2. Shell Programming and Scripting

Needed shell script to append desired text to each line in a file

Hi, I had generated a report in my tool as followsoutput.txt 43.35 9 i needed the script to generate a new file like below i want to append the text to each of these lines of my filenewoutputfile.txt should be Total Amount : 43.35 Record Count:9 Regards, Vasa Saikumar. ... (2 Replies)
Discussion started by: hemanthsaikumar
2 Replies

3. Emergency UNIX and Linux Support

Script to fill the file system mount with empty files to desired size

We are regularly using for our testing, where we are manually filling up the mount with desired size with following command dd if=/dev/zero of=file_2GB bs=2048000 count=2000 We are planning to automate the task where taking input for % of size as one input and the name of the file system... (8 Replies)
Discussion started by: chandu123
8 Replies

4. Shell Programming and Scripting

Script not working in cron but working fine manually

Help. My script is working fine when executed manually but the cron seems not to catch up the command when registered. The script is as follow: #!/bin/sh for file in file_1.txt file_2.txt file_3.txt do awk '{ print "0" }' $file > tmp.tmp mv tmp.tmp $file done And the cron... (2 Replies)
Discussion started by: jasperux
2 Replies

5. Shell Programming and Scripting

Cron job is not working in the desired manner on IBM AIX

Hi, I have created a cron job on IBM AIX but it is not working in desired manner ! Here are the steps which I have followed :- #!/bin/ksh #------------------------------------------------------------------ find /some/file/at/the/user/side/test.log -exec cp {}... (8 Replies)
Discussion started by: acidburn_007
8 Replies

6. Shell Programming and Scripting

Script is not working from cron while working manually

Hello, I am facing a very strange problem when I run my script manuallu ./Fetchcode which is using to connect with MKS integrity from linux end it workks fine but when I run it from cron it doesn't work.Can someone help me 1) How could I check my script when it is running from cron like... (3 Replies)
Discussion started by: anuragpgtgerman
3 Replies

7. UNIX for Dummies Questions & Answers

if statement not working as desired

Hello all, I am trying to write a post-commit hook script using bash script. What I am trying to do here is: Developers check in their files to a branch. I check the repository and based on the commit I email QA people. QA verifies and moves the files to a prod branch and email is sent... (1 Reply)
Discussion started by: kminkeller
1 Replies

8. Shell Programming and Scripting

C shell integer tests, less than and more than, not working as desired

Hello, I am creating a script that gives me system load info when i start a shell or log in via ssh(in the /etc/profile.d/ folder). I created it successfully for bash and want it to work with c-shell as well. This is where i'm having problems, the integer test in the if sentence does not work... (3 Replies)
Discussion started by: str1fe
3 Replies

9. Shell Programming and Scripting

script not giving the desired output

Hi, I have a script in which an entry like this ..... FILENAME_B="PIC_${DATE}0732*.JPG" The script connects to an ATM and pull a pic file from it.The format for the file is like PIC_2008061400000001.JPG in the ATM. Means 1st 8 digit is the date(YYYYMMDD) field 2nd 8 digit means hrs... (2 Replies)
Discussion started by: Renjesh
2 Replies

10. UNIX for Dummies Questions & Answers

chmod not working as desired

my file had permission -rw-rw-r-- I did chmod +rwx, expecting everything to now be rwx, but it is -rwxrwxr-x why doesn't o have x permission? thanks. (2 Replies)
Discussion started by: JamesByars
2 Replies
Login or Register to Ask a Question