The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Using wget and check for non-zero files weatherboys Shell Programming and Scripting 3 08-11-2008 11:17 PM
check for FILES existence mpang_ Shell Programming and Scripting 3 06-28-2006 03:51 AM
Check for specific files woosaah Shell Programming and Scripting 5 01-24-2006 03:37 PM
How to check no. of files open currently max_min SUN Solaris 1 08-11-2005 02:58 PM
How to check the files are Identical or not? redlotus72 UNIX for Dummies Questions & Answers 3 07-06-2005 05:22 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-15-2006
Registered User
 

Join Date: Feb 2006
Posts: 66
Check 2 files ???

Hi all,

I know how to count lines, count byte of a file, but really dont know how to compare line , I am newbie and hope you can help me to learn more about UNIX.
Here is my problem.
====
How :

1. File A (Flatfile with NAME|DATE|ID1|ID2|ID3|ID4|ID5)
CJKA|2005-12-10-08.01.30.000000|1111111111|ECI|1112221111|1113331111|1114441111
DMCH|2005-12-10-08.28.00.000000|1111113333|CCCOSSR|1112223333|1113333333|1114443333
DLMQ|2005-12-11-01.00.00.000000|1111117777|STLITE|1112227777|1113337777|1114447777
DMCH|2005-12-10-08.20.00.000000|1111114444|MTRRD|1112224444|1113334444|1114444444
CJKA|2005-12-10-08.10.00.000000|1111112222|OMCRTVI|1112222222|1113332222|1114442222
R1L7|2005-12-10-08.11.00.000000|1111115555|CLAIMS|1112225555||
DLMQ|2005-12-10-08.00.00.000000|1111116666|QAS1|1112226666|1113336666|1114446666
DLMQ|2005-12-11-01.10.00.000000|1111118888|SVCPLN|1112228888|1113338888|1114448888
CJKA|2005-12-10-08.13.30.000000|1111119999|OMCRTVI|1112229999|1113339999|1114449999

2. File B ( 4 lines)
records='9'
bytes='724'
CJKA|2005-12-10-08.01.30.000000|1111111111|ECI|1112221111|1113331111|1114441111
CJKA|2005-12-10-08.13.30.000000|1111119999|OMCRTVI|1112229999|1113339999|1114449999

How we write a ksh script to compare and give another output file

1. a. Check record count in file A is equal 9 in file B.
b. Check byte count in file A is equal line 2 file B 724
c. First record in File A is line 4 in file B
d. last record in file A is line 4 in File B

If it did not match then give the error do not match . Which one is not match

2. If it is match then give the out put
File C name is yyyymmdd.dat in 2nd field of file A , like 20051210.dat , it will be a flatfile
NAME|DATE||||ID4|ID3
====

Thanks for sharing your knowledge .
Reply With Quote
Forum Sponsor
  #2  
Old 02-15-2006
Registered User
 

Join Date: Feb 2006
Location: Southern England
Posts: 102
look at man:

join
sort
uniq
Reply With Quote
  #3  
Old 02-15-2006
Registered User
 

Join Date: Feb 2006
Posts: 66
I really dont see sort, uniq in here

Here is what I did for 1c and 1d
====

$AFIRST=(head -1 A)
$BTHREE=(cat B | sed -n 3p)
if [[ $AFIRST = $BTHREE ]];
then
print "they match"
else
print "they don't match"
fi


ALAST=$(tail -1 A)
BFOUR=$(cat B | sed -n 4p)
if [[ $ALAST = $BFOUR ]]
then
print "they match"
else
print "they don't match"
fi
=======

I got this part for 1a and 1b
ALINES=$(cat A | wc -l)
BFIRST=$(head -1 B)

how do you compare ALINE=9 and BFRIST=records'9' ; how to have only 9 = 9
Reply With Quote
  #4  
Old 02-15-2006
Registered User
 

Join Date: Feb 2006
Posts: 61
i guess i'm kinda lost in what you're trying to do. bigearsbilly's sugestion of using uniq as an option actually sounds like a pretty good suggestion to me.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0