![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| awk - comparing files | dbrundrett | Shell Programming and Scripting | 4 | 08-22-2008 07:23 AM |
| Comparing two files | superstar003 | Forum Support Area for Unregistered Users & Account Problems | 1 | 05-08-2008 12:34 AM |
| Comparing two files.. | padarthy | Shell Programming and Scripting | 1 | 08-29-2007 05:01 AM |
| Comparing two files... | paqman | Shell Programming and Scripting | 12 | 08-08-2007 12:45 AM |
| comparing shadow files with real files | terrym | UNIX for Advanced & Expert Users | 4 | 02-08-2007 11:38 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi,
I have some text files. I need a separate shell say 1.sh in which i can open a particular text file and compare with another txt file. For example: 1.log.txt contains apple ball cat goat 2.log.txt contains goat cat lion apple fox In my i.sh i need to write script to compare this two files and write the the o/p.The output should be written onto two different files such that one file contains the words that match and another contains the words that do not match.That is after i run 1.sh i should get common.txt and notcommon.txt common.txt should contains words present in both(common to both 1.og.txt & 2.log.txt ).i.e; apple ca goat nocommon.txt should contain the words present only in 2.log.txt and not in 1.log.txt . i.e; lion fox Thanks in advance JS |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
I have searched the forum and got the answer for this...I used "comm"
Thanks JS |
|
#3
|
|||
|
|||
|
Remmeber that comm will work only for sorted files.
|
|
#4
|
|||
|
|||
|
comm
Hi,
If you are not considering the sequence of the line in the original txt file. I think you can use comm command. Try below one. Code:
sort file1 > file1.temp sort file2 > file2.temp comm -12 file1.temp file2.temp > common.txt comm -13 file1.temp file2.temp >uncommon.txt |
|
#5
|
|||
|
|||
|
That is a better code than waht i tried ..
i didnot sort my source files but it was almost in a sorted way .. But its always a good method to sort the files before compiling it .. Thanks a lot for the quote .. Regards JS |
|
#6
|
|||
|
|||
|
thanks for pointing it out .. Actually teh fils where sorted. Hence I ddint go for sorting .. The example i gave was for the name sake ..its not teh actual format of my file ..
thanks a lot for pointing it out .. because i didnt know about it .. its going to help me in the future .. thanks a lot JS |
|||
| Google The UNIX and Linux Forums |