Comparing Data file with Crtl file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparing Data file with Crtl file
# 1  
Old 04-17-2013
Comparing Data file with Crtl file

Hi,
I need to compare a file with its contents matching to that of another file(filename , received date and record count).
Lets say has File A original data
Code:
Ex -
1,abc,1234
2,bcd,4567
3,cde,8901

and File B has details of File A
Code:
Ex-
FILEA.TXT|06/17|2010|3
(filename)|(received date)|(record count)

I need to fetch the details(filename , received date and record count) File A ,and must be compared with File B and it should match.I wrote a code which covers all the requirements but it throws me an error. It throws error at line 62 stating ']' missing and line 72 : argument expected. Kindly have a look at my script and let me know where I went wrong.

Original Script
Code:
echo "Initialising the run time parameter for FOLDER path..."
cd $path   #path will be given here
echo "\n Folder path of the unzipped files and CNTRL file: $1 "
echo "\n \n Reading the content from CNTRL file and asssigning the values to variables..."
while IFS='|' && read fname Process_dt rec_cnt 
do
 echo "\n $fname $Process_dt $rec_cnt "
 echo "\n Checking if the File exist in the folder..."
 if [ -f $fname ]  ; then    
  echo "\n $fname Exist"
  echo "\n \n Reading linecount for the corresponding file and storing it in a variable..."
 
  cat $fname | wc -l | read linecount  
  echo "\n Reading Processdate for the corresponding file and storing it in a variable..."
  ls -l | awk '{print $6 $7 S8}'| nawk ' { months="  JanFebMarAprMayJunJulAugSepOctNovDec";date=$2;month=index(months,substr($1,1,3))/3; year=$3; printf("%02s/%02s/%s
\n",month,date,year)}'|read Proc_dt;
  echo "\n checking if record count and Process date of the file matches with the CNTRL file entry..."
   if [ ($linecount -eq $rec_cnt) && ($Proc_dt -eq $Process_dt) ]  ; then  
     echo "\n \n Record Count and Process date matches from both files"
     return 0  
   else 
     if [ ($linecount -ne $rec_cnt)]
      echo "\n \n Record Count doesnot match"
      return 1
     fi
   else
     echo "\n \n Process date doesnot match" 
     return 1
   fi
 fi
 echo "Passing the run time parameter for CNTRL file name..."
done < POR.CRTl 
echo " Filename,Record count and Process date validated against file $2"

I will be incorporating this into a cmd task where I will pass path and CRTL file name as variable.

--
# 2  
Old 04-17-2013
Code:
echo "Initialising the run time parameter for FOLDER path..."
cd $path   #path will be given here
echo "\n Folder path of the unzipped files and CNTRL file: $1 "
echo "\n \n Reading the content from CNTRL file and asssigning the values to variables..."
while IFS='|' && read fname Process_dt rec_cnt 
do
 echo "\n $fname $Process_dt $rec_cnt "
 echo "\n Checking if the File exist in the folder..."
 if [ -f $fname ]  ; then    
  echo "\n $fname Exist"
  echo "\n \n Reading linecount for the corresponding file and storing it in a variable..."
 
  linecount=$(wc -l $fname | cut -d' ' -f1)
  echo "\n Reading Processdate for the corresponding file and storing it in a variable..."
  Proc_dt=$(stat -c %y $fname | awk -F'[- ]' '{print $2 "/" $3 "/" $1}'
  echo "\n checking if record count and Process date of the file matches with the CNTRL file entry..."
   if [ $linecount -eq $rec_cnt && $Proc_dt -eq $Process_dt ]  ; then  
     echo "\n \n Record Count and Process date matches from both files"
     return 0  
   else 
     if [ $linecount -ne $rec_cnt ] # A space was missing between rec_cnt and ]
      echo "\n \n Record Count doesnot match"
      return 1
     fi
   else
     echo "\n \n Process date doesnot match" 
     return 1
   fi
 fi
 echo "Passing the run time parameter for CNTRL file name..."
done < POR.CRTl

# 3  
Old 04-18-2013
Comparing Data file with Crtl file

It throws error at
Proc_dt=$(stat -c %y $fname | awk -F'[- ]' '{print $2 "/" $3 "/" $1}'

saying ( expected;
and

else
echo "\n \n Process date doesnot match"



saying else unexpected

Last edited by Prashanth B; 04-18-2013 at 02:28 AM.. Reason: missed full reply
# 4  
Old 04-18-2013
Code:
Proc_dt=$(stat -c %y $fname | awk -F'[- ]' '{print $2 "/" $3 "/" $1}')

Add closing ) character.
# 5  
Old 04-18-2013
Well you also have a non-numeric value in variable: Proc_dt because of following statement:
Code:
Proc_dt=$(stat -c %y $fname | awk -F'[- ]' '{print $2 "/" $3 "/" $1}')

And you are trying to perform a numeric comparison. I would also suggest to replace the if statement syntax to:
Code:
if [ $linecount -eq $rec_cnt ] && [ $Proc_dt -eq $Process_dt ]

# 6  
Old 04-18-2013
Yes, the following is wrong, as yoda noted:
Code:
if [ $linecount -eq $rec_cnt && $Proc_dt -eq $Process_dt ]  ; then

The other way to correct (one test, two conditions required) is:
Code:
if [ $linecount -eq $rec_cnt -a $Proc_dt -eq $Process_dt ]; then

# 7  
Old 04-18-2013
thanks for timely help..Im not getting that error now.
but should we use ; in IF statements...?? Im not sure about this. to fetch process date I used
ls -l | awk '{print $6 $7 S8}'| nawk ' { months=" JanFebMarAprMayJunJulAugSepOctNovDec";date=$2;month=index(months,substr($1,1,3))/3; year=$3; printf("%02s/%02s/%s",month,date,year)}'|read Proc_dt;

wont it work?
Also my first echo statement is printing , my script is executing but only last echo is being executed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Comparing 2 column of a file with the lines in another file

Hi I have 2 files which are tab delimited. file1 chr1 5 10 P1 KR4 chr1 10 20 1H LA1 R0 TA1 file2 P1 G6 13.27 0.2425 P1 KR4 18.79 0.3060 P1 DND1 19.44 0.2833 N1 DH1 0.99 1.08 1H R0 0.9 NA LA1 R0 90 0.9 TA1 KR4 1.8 8.9 TA1 R0 9.7 99I want to check whether first 2 columns in file2 (column... (1 Reply)
Discussion started by: raj_k
1 Replies

2. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

3. Shell Programming and Scripting

Script for Comparing directories and file from a text file

Hello all, I need to write a script which has following requirement: Need to read the filenames from text file and then search for the above read files in the required directory and if match found backup them in a backup folder. And also need to compare and verify whether the files in the... (7 Replies)
Discussion started by: saurau
7 Replies

4. Shell Programming and Scripting

Retrieve data from one file comparing the ID in the second file

Hi all, I have one file with IDs Q8NDM7 P0C1S8 Q8TF30 Q9BRP8 O00258 Q6AWC2 Q9ULE0 Q702N8 A4UGR9 Q13426 Q6P2D8 Q9ULM3 A8MXQ7 I want to compare ID file with another file which has complete information about these IDs and also about other IDs which are not in the above ID file. As... (10 Replies)
Discussion started by: kaav06
10 Replies

5. UNIX for Dummies Questions & Answers

Mapping a data in a file and delete line in source file if data does not exist.

Hi Guys, Please help me with my problem here: I have a source file: 1212 23232 343434 ASAS1 4 3212 23232 343434 ASAS2 4 3234 23232 343434 QWQW1 4 1134 23232 343434 QWQW2 4 3212 23232 343434 QWQW3 4 and a mapping... (4 Replies)
Discussion started by: kokoro
4 Replies

6. Shell Programming and Scripting

Remove duplicate lines from first file comparing second file

Hi, I have two files with below data:: file1:- 123|aaa|ppp 445|fff|yyy 999|ttt|jjj 555|hhh|hhh file2:- 445|fff|yyy 555|hhh|hhh The records present in file1, not present in file 2 should be writtent to the out put file. output:- 123|aaa|ppp 999|ttt|jjj Is there any one line... (3 Replies)
Discussion started by: gani_85
3 Replies

7. Shell Programming and Scripting

Comparing rows in same file and writing the result in new file

Help needed... Can you tell me how to compare the last two couple entries in a file and print their result in new file..:confused: I have one file Check1.txt \abc1 12345 \abc2 12327 \abc1 12345 \abc2 12330 I want to compare the entries in Check1 and write to... (1 Reply)
Discussion started by: kichu
1 Replies

8. Shell Programming and Scripting

Need help in comparing a file with log file: perl code

Dear Members, I need a perl code: 1. Which will open first file with two columns separated by tab: 37 Distribution and seasonal variation of trace metals 85 Seasonal variability of the mixed layer in the central Bay 99 Dynamics of transparent exopolymeric particles (TEP) 103 Bacterial... (0 Replies)
Discussion started by: srsahu75
0 Replies

9. Shell Programming and Scripting

Comparing data inside file

Hi Everyone, I will try to explain my question please forgive my english here. I am looking for shell script or command that can compare data in the files. I have 50 files in one directory test1 test2 test3 ....so on. I want to compare data in each files with each other and output each... (4 Replies)
Discussion started by: email-lalit
4 Replies

10. Shell Programming and Scripting

Comparing data in file with values in table

Hi, I want to calculate the number of pipe delimiters in a file for all lines seperately. For eg:i have a file Project.txt Mohit|chawla|123|678 File1|File2|345|767|678 And my file contains many lines like this it shd give me the output as 4 5 or give me the output for all the... (0 Replies)
Discussion started by: Mohit623
0 Replies
Login or Register to Ask a Question