File comparision line by line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File comparision line by line
# 1  
Old 06-17-2013
File comparision line by line

Hi,

I want to compare 2 files and get output file into seperate folder.

Both file names will change daily with timestamp (ex: file1_06_17_2013_0514), so i can't mention the file names in the script to compare,

but i need to compare these 2 files daily and generate output to another folder.

Can you please help to prepare script to get this done?

Thanks.
# 2  
Old 06-17-2013
What have you tried so far?
Also, specify the input output files (at least samples, if files are big)
# 3  
Old 06-17-2013
i have copied the files to the folder, doing comparision manually by using "comm" command and place output file in to other folder....but daily we can't do it manually, need to automate to get that files and compare.
# 4  
Old 06-18-2013
Try using find with time stamps.
# 5  
Old 06-20-2013
thanks for reply RudiC, but how come we find out the date? files can be y'day or today or 3days back files?

Only here, it has to take 2 files in that folder and compare.
# 6  
Old 06-20-2013
Quote:
Originally Posted by rkrish123
thanks for reply RudiC, but how come we find out the date? files can be y'day or today or 3days back files?

Only here, it has to take 2 files in that folder and compare.
What we are missing is a description of how you determine which two files you want to compare when you do it manually.

If today's year, month, and day are 2013, 06, and 20, what are the names of the files you want to compare when you run your script today? Are there other files in your directory whose names might be "similar" to the names of the files you want to compare but should be ignored?
# 7  
Old 06-20-2013
The files can be any date, it may contain today day or y'day....

i can't hardcode the filenames as filename changes daily with new time stamps...
Code:
Aggr_New_06_15_2013_1944.txt
Aggr_New_06_19_2013_1944.txt

These 2 files are in /tmp/test folder, i have to compare and get difference in other file like Aggr_New.txt in same folder or any other folder.

Aggr_New_06_15_2013_1944.txt has below records
Code:
ACCOUNT|497|1108000-new|Jun|2045.00
ACCOUNT|497|Mmnfy-new|Jun|1903.00
ACCOUNT|497|922857-new|Jun|2045.00


Aggr_New_06_19_2013_1944.txt has below records
Code:
ACCOUNT|497|1108000-new|Jun|2045.00
ACCOUNT|497|Mmnfy-new|Jun|1903.00
ACCOUNT|497|922857-new|Jun|2045.00
ACCOUNT|497|922865-new|Jun|4509.00
ACCOUNT|497|922987-new|Jun|3249.00
ACCOUNT|497|1|Jun|867.00

Output:
Code:
ACCOUNT|497|922865-new|Jun|4509.00
ACCOUNT|497|922987-new|Jun|3249.00
ACCOUNT|497|1|Jun|867.00


Last edited by Scott; 07-03-2013 at 05:23 PM.. Reason: Please use code tags for code and data
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get an output of lines in pattern 1st line then 10th line then 11th line then 20th line and so on.

Input file: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 (6 Replies)
Discussion started by: Sagar Singh
6 Replies

2. Shell Programming and Scripting

How to read file line by line and compare subset of 1st line with 2nd?

Hi all, I have a log file say Test.log that gets updated continuously and it has data in pipe separated format. A sample log file would look like: <date1>|<data1>|<url1>|<result1> <date2>|<data2>|<url2>|<result2> <date3>|<data3>|<url3>|<result3> <date4>|<data4>|<url4>|<result4> What I... (3 Replies)
Discussion started by: pat_pramod
3 Replies

3. Shell Programming and Scripting

Need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line...

Hello, I need a program that read a file line by line and prints out lines 1, 2 & 3 after an empty line... An example of entries in the file would be: SRVXPAPI001 ERRO JUN24 07:28:34 1775 REASON= 0000, PROCID= #E506 #1065: TPCIPPR, INDEX= 003F ... (8 Replies)
Discussion started by: Ferocci
8 Replies

4. Shell Programming and Scripting

perl: comparision of field line by line in two files

Hi everybody, First I apologize if my question seems demasiad you silly, but it really took 4 days struggling with this, I looked at books, forums ... And Also ask help to a friend that is software developer and he told me that it is a bad idea do it by perl... but this is my problem. I moved to... (8 Replies)
Discussion started by: Thelost
8 Replies

5. Shell Programming and Scripting

Read file line by line and process the line to generate another file

Hi, i have file which contains data as below(Only sample shown, it may contain more data similar to the one shown here) i need to read this file line by line and generate an output file like the one below i.e based on N value the number of MSISDNs will vary, if N=1 then the following... (14 Replies)
Discussion started by: aemunathan
14 Replies

6. Shell Programming and Scripting

[Solved] Problem in reading a file line by line till it reaches a white line

So, I want to read line-by-line a text file with unknown number of files.... So: a=1 b=1 while ; do b=`sed -n '$ap' test` a=`expr $a + 1` $here do something with b etc done the problem is that sed does not seem to recognise the $a, even when trying sed -n ' $a p' So, I cannot read... (3 Replies)
Discussion started by: hakermania
3 Replies

7. Shell Programming and Scripting

Line by Line Comparision of 2 files and print only the difference

Hi, I am trying to find an alternative way to do tkdiff. In tkdiff the gui compares each line and highlights only the differences. for eg: John works at McDonalds s(test) He was playing guitar tywejk John works in McDonalds 9908 He was playing guitar I am... (1 Reply)
Discussion started by: naveen@
1 Replies

8. UNIX for Advanced & Expert Users

how do you parse 1 line at a time of file1 ie. line(n) each line into new file

File 1 <html>ta da....unique file name I want to give file=>343...</html> <html>da ta 234 </html> <html>pa da 542 </html> and so on... File 2 343 234 542 and so on, each line in File 1 one also corresponds with each line in File 2 I have tried several grep, sed, while .. read, do,... (4 Replies)
Discussion started by: web_developer
4 Replies

9. Shell Programming and Scripting

file comparision by line

i have two files and i want to compare these two it shoud print those lines which are not in 2nd file a.txt 1236,AB,0 2345,CD,1 5679,EF,1 9123,AA,1 9223,AA,0 b.txt 1234,AB,0 2345,CD,1 5678,EF,1 9123,AA,0 o/p 1236,AB,0 5679,EF,1 9123,AA,1 9223,AA,0 (6 Replies)
Discussion started by: aaysa123
6 Replies
Login or Register to Ask a Question