Record count checking for multiple files through for-loop


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Record count checking for multiple files through for-loop
# 1  
Old 05-28-2014
Record count checking for multiple files through for-loop

Hi Friends,

I wrote one shell script to check the record count in two files and that will send us the notification activity if found zero record count.

What i did is I created for loop and checking the count for both of the files but what is happening is for first file has data then it's getting exit and not checking another file count.

I have prepared script as below please check it and correct me if anything wrong.

Code:
#!/bin/sh
a=/tjx/iisNAS/data/edw/fp/output/common/sample.txt
b=/tjx/iisNAS/data/edw/fp/output/common/sample1.txt
for file in `wc -l $a |awk -F " " '{print $1}'` `wc -l $b |awk -F " " '{print $1}'`
do
if [ $file -eq 0 ];
then
mailx -s " $file Data is not available in lookup" 
exit 1
else
mailx -s " $file /tjx/iisNAS/data/edw/fp/output/common/sample.txt Data is available in lookup" abc@yahoo.com
exit 0
fi

Thanks in advance.

Last edited by vgersh99; 05-28-2014 at 11:57 AM.. Reason: code tags, please!
# 2  
Old 05-28-2014
Not sure I grasp your logics. Why dont you try like this (untested):
Code:
a=/tjx/iisNAS/data/edw/fp/output/common/sample.txt
b=/tjx/iisNAS/data/edw/fp/output/common/sample1.txt
for file in $a $b
do if [ 0 -eq $(wc -l $file) ]
   then mailx ...
        exit 1
   else mailx ...
        exit 0
   fi
done

# 3  
Old 05-28-2014
Thanks a lot friend...
I will try now..
# 4  
Old 05-30-2014
Better use
Code:
[ 0 -eq $(wc -l <$file) ]

# 5  
Old 05-30-2014
THanks friend..

I tried it was working now...

Thanks a lot..could you please provide your email ID to contact..

---------- Post updated at 09:37 AM ---------- Previous update was at 08:55 AM ----------

Hi Friend,

I was not working for me when first file found data in file then it's getting exit and completed it's not going to check for another file.

let me check

---------- Post updated at 09:41 AM ---------- Previous update was at 09:37 AM ----------

Hi Rudy,

I have implemented the logic given below.


Code:
a=/tjx/iisNAS/data/edw/fp/output/common/sample.txt
b=/tjx/iisNAS/data/edw/fp/output/common/sample1.txt
for file in $a $b
do if [ 0 -eq $(wc -l /tjx/iisNAS/data/edw/fp/output/common/sample.txt) && 0 -eq $(wc -l /tjx/iisNAS/data/edw/fp/output/common/sample1.txt)] && 
   then mailx ...
        exit 1
   else mailx ...
        exit 0
   fi
done


Last edited by Franklin52; 05-30-2014 at 03:23 PM.. Reason: Please use code tags
# 6  
Old 05-30-2014
Quote:
Originally Posted by victory
Thanks a lot..could you please provide your email ID to contact..
Discussion on unix.com is intended to stay on unix.com so that it provides benefit to future readers.
# 7  
Old 06-01-2014
Why do you define the a and b variables, use them for the for loop, and then put in the filenames as fixed strings? And what is the && for at the end of the if line?
The reason for your complaint is called "shortcircuit evaluation" and is used in many languages: If the first operand in an and operation fails, the result is known and the second is not needed to be evaluated.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

CSV joining and checking multiple files

Hello, For our work we use several scripts to gather/combine data for use in our webshop. Untill now we did not had any problems but since a couple days we noticed some mismatches between imports. It happened that several barcodes where matched even though it was a complete other product. Of... (19 Replies)
Discussion started by: SDohmen
19 Replies

2. Shell Programming and Scripting

Checking File record equal to multiple of 70 or nearest number to multiple of 70

Hello, I have a file with below content - Example 3 6 69 139 210 345 395 418 490 492 I would like the result as - Multiple of 70 or nearest number in the file less than the multiple of 70 69 139 (5 Replies)
Discussion started by: Mannu2525
5 Replies

3. Shell Programming and Scripting

Shell script for field wise record count for different Files .csv files

Hi, Very good wishes to all! Please help to provide the shell script for generating the record counts in filed wise from the .csv file My question: Source file: Field1 Field2 Field3 abc 12f sLm 1234 hjd 12d Hyd 34 Chn My target file should generate the .csv file with the... (14 Replies)
Discussion started by: Kirands
14 Replies

4. Programming

awk to count occurrence of strings and loop for multiple columns

Hi all, If i would like to process a file input as below: col1 col2 col3 ...col100 1 A C E A ... 3 D E G A 5 T T A A 6 D C A G how can i perform a for loop to count the occurences of letters in each column? (just like uniq -c ) in every column. on top of that, i would also like... (8 Replies)
Discussion started by: iling14
8 Replies

5. Shell Programming and Scripting

count of record in files

Hi all, I have written a scripts which count number of lines in all the files in a directory and write in a text file. I don't know how to format it while writing. OS suns solaris 10 my scripts is as below for i in /ersdg3/ERS/ERS_INPUT_LOGS/RIO/LOGS/RIO_02-Aug-2012/ *.LOG do echo... (11 Replies)
Discussion started by: guddu_12
11 Replies

6. Shell Programming and Scripting

Checking the existance of multiple files

I am trying to execute the following command to check the existance of a file (which has a date timestamp on it). If there are more than one file, then also it should give me 'success' result. if then <do some work> else <no files> fi Since there are more than one... (18 Replies)
Discussion started by: vivek_damodaran
18 Replies

7. Shell Programming and Scripting

Comparison of record count of two files

Hi, I have one text file and zip file in UNIX directory.The Zip file contains another text file. For Ex: Text File Name = Req_file.txt Zip file Name= Response_file.txt_04072009_121548.gz Zip file contains one text file that name is Response_file.txt I want to compare the record... (1 Reply)
Discussion started by: praka
1 Replies

8. Shell Programming and Scripting

bash if loop for checking multiple parameters

Hello, I've got next problem: I want to examine at the beginning of a script in an if loop that: 1. Is there 4 parameters given 2. If first state is true then: is there switches -e and -d? 3. At the end, how can i indentify them as variebles regardlees to its order. I was thinking like... (2 Replies)
Discussion started by: szittyafergeteg
2 Replies

9. Shell Programming and Scripting

checking count of files and exiting

Hi All Please see the script below for file in ${filelist }; do if ]; then if ]; then print " $(date) STEP 6 ------- Copying $file to $destpath" fi if ! cp $ftppath/$file $destpath 2> /dev/null; then writeToLog "ERROR: ${0##*/} - $upartition Could not copy file $file" if ]; then... (1 Reply)
Discussion started by: king007
1 Replies

10. Shell Programming and Scripting

replaying a record count with another record count

i use unix command to take the record count for a file1 awk 'END{print NR}' filename i already have a file2 which conatin the count like ... .. rec_cnt=100 .. .. I want to replace the record in the file2 using the record i take from file1. suggest me some simple ways of doing it... (2 Replies)
Discussion started by: er_zeeshan05
2 Replies
Login or Register to Ask a Question