Script not working as desired


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

Can you please explain just the 3 main loops in your script if you don't mind?

I will appreciate if you can so that I will not have gaps in my understanding and what's actually it is doing.

Once again I appreciate your time and great scritping power.
# 23  
Old 07-25-2006
I will update tomorrow with explanation, I'm dealing with an urgent issue here at the moment.
# 24  
Old 07-26-2006
Code:
awk -v complete_file=${1}_$(date+%Y%m%d)

 'FNR != 1 {       skip the header records

data[NR] = $0   store the current line in an array indexed by the record number
out=FILENAME "new" set the value of out to the name of the current file being processed, with "out" appended.
file[NR]=out      tell it which file this record goes in
records[out]=NR keep the line index of the last line of each file

}



END {
        for ( r in records ) {
                sum += data[records[r]]    sum the total number of expected records
        }

        if ( sum != NR - (ARGC * 2) ) {
        compare the number of records with the expected number of records(subtract 2 per file)
                print "error"
        }
        else {
                for ( i in file ) { do this for every stored record in file
                        if ( i != records[file[ i ]] ) { 
skip the expected number of records line for each file
                                print data[i] > file[i]
                                print data[i] > complete_file
                        }
                }
                close(file[i])
        }
        close(complete_file)
}
' $files

# 25  
Old 07-26-2006
Reborg,

Thank you very much for the explanation my friend.
# 26  
Old 07-27-2006
Reborg,

If I want to throw the error along with the filename having error in rowcount what should I change? Just specifying FILENAME at error portion is not throwing the file having error. Kindly suggest.
# 27  
Old 07-27-2006
Hmm, that's awkward, but this might work. I havn't been able to test it however.

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 ) {
                r_count=-1
                for ( j in file ) {
                        if ( file[j] == r ) {
                                r_count++
                        }
                }
                if ( r_count != data[records[r]]) {
                      printf "Record count error in : %s\n", substr(r, 0, length(r)-3)
                      exit(1);
                }
        }

        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

# 28  
Old 07-28-2006
Reborg,

Sorry I am bad!!! I am getting the below error: Are we missing brackets some where. I tried with some changes but it didn't work.

syntax error The source line is 37.
The error context is

>>> <<<
awk: The statement cannot be correctly parsed.
The source line is 37.
awk: There are 2 missing } characters
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