Comparing two files (comm or awk) - help - very urgent pls


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparing two files (comm or awk) - help - very urgent pls
# 1  
Old 01-05-2006
Error Comparing two files (comm or awk) - help - very urgent pls

I an unix newbie and am confused about the working of "comm".

I have two files to be compared and the three columns of output after comparison should be stored a three separate files.

File abc
--------
pink
orange
green
blue
black
maroon


File xyz
---------
pink
yellow
grey
black
blue
maroon

I use :1) comm -23 abc xyz (to get lines unique to abc)
2) comm -13 abc xyz (to get lines unique to xyz)
3) comm -12 abc xyz (to get lines common to both abc and xyz files)

output of 1) is :
--------------
orange
green
blue
black
maroon

output of 2) is:
---------------
yellow
grey
black
blue
maroon

output of 3) is :
---------------
pink (?!?!?)


this is strange to me as i find the lines containing "maroon" is common to both files.. still not pulled out by (3).

Can somebody explain where I missed?

It would be great if help is given on usage of "awk" to do something similar. (In fact, the files I've to compare are much larger than I explained my problem with).

Thanks in advance
Sirisha
# 2  
Old 01-05-2006
refer the man

The man says ' comm - select or reject lines common to two sorted files'. your fileks are not sorted. Try executing after sorting them.
# 3  
Old 01-05-2006
Quote:
Originally Posted by manthasirisha
File abc
--------
pink
orange
green
blue
black
maroon

File xyz
---------
pink
yellow
grey
black
blue
maroon

I use :1) comm -23 abc xyz (to get lines unique to abc)
2) comm -13 abc xyz (to get lines unique to xyz)
3) comm -12 abc xyz (to get lines common to both abc and xyz files)

output of 1) is :
--------------
orange
green
blue
black
maroon

output of 2) is:
---------------
yellow
grey
black
blue
maroon

output of 3) is :
---------------
pink (?!?!?)


this is strange to me as i find the lines containing "maroon" is common to both files.. still not pulled out by (3).
Did you not find the results of 1 and 2 strange? Yet you only noticed the results of 3 to be very different. 1 and 2 also are not showing up the proper results. You need to sort the input files.

The POSIX specification has this to say
Code:
If the lines in both files are not ordered according to the collating sequence of the current locale, 
the results are unspecified.

Vino
# 4  
Old 01-05-2006
Error Comparing two files (Comm) ..If these are the input files

Thanks a lot ranj@chn and vino!

That was a silly overlooking mistake, but now i got it.

In fact these are my actual input files.

seqfile
------
ORDERNO ORDERDATE ORDERDESC STREET CITY

1
2
3
4
5
6
7
8
9
10

target
------
ORDERNO ORDERDATE ORDERDESC STREET CITY
2
3
4
5


"target" is file generated from the "seqfile" by extracting a few rows (Content in all the fields in the target is same as that of seqfile.. no modifications). Now that seqfile and target are sorted, comparing these two to find out common lines (comm -12 seqfile target), gives me "null" (no output).

Correct me if I'm wrong in saying that I should get an output equivalent to the "target" file.
Also what is the correct output of "comm - 13 seqfile target" ? Is it ok if I get the target file as the output of this statement?

Many thanks,
Sirisha
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Need urgent help in comparing two fields in two files

Hi all, I have two files as below. I need to compare field 2 of file 1 against field 1 of file 2 and field 5 of file 1 against filed 2 of file 2. If both matches , then create a result file 1 with first file data and if not matches , then create file with first fie data. Please help me in... (1 Reply)
Discussion started by: sivarajb
1 Replies

2. Shell Programming and Scripting

Help Me Pls Its Urgent!!!!!!!!!!!!!!!!

Hi, These are the text file I have //input1.txt// cd dir1/dir2/pg1.txt cd dir3/dir4/pg2.txt cd dir88/dir5/pg4.txt cd dir7/dir6/pg5.txt cd dir8/dir9/pg7.txt And each text file has some text. Now I have to write a shell script which reads input1.txt and changes the directory as shown... (1 Reply)
Discussion started by: bhavanabahety
1 Replies

3. Shell Programming and Scripting

Urgent ...pls Sorting files based on timestamp and picking the latest file

Hi Friends, Newbie to shell scripting. Currently i have used the below to sort data based on filenames and datestamp $ printf '%s\n' *.dat* | sort -t. -k3,4 filename_1.dat.20120430.Z filename_2.dat.20120430.Z filename_3.dat.20120430.Z filename_1.dat.20120501.Z filename_2.dat.20120501.Z... (1 Reply)
Discussion started by: robertbrown624
1 Replies

4. Shell Programming and Scripting

pls help me very urgent

will post again (1 Reply)
Discussion started by: revertback
1 Replies

5. Shell Programming and Scripting

Pls Help me.. soon. Very urgent

I have downloaded the Putty SSH configuration. I have entered my Host name as illinois.engr.sjsu.edu and i am trying to save that. But i am unable to save. Also i opened the session and entered my log in name But it says using keyboard interactive authentication.I am not able to get into $ ... (2 Replies)
Discussion started by: VamsiVasili
2 Replies

6. UNIX for Dummies Questions & Answers

URGENT :pls help

Following is d code snipet #!/bin/ksh retVal=`sqlplus -s user/passwd\@oracle_sid <<EOF SET SERVEROUTPUT ON SIZE 100000 DECLARE STATUS_VALUE VARCHAR2(1); BEGIN SELECT temp1 INTO STATUS_VALUE FROM sai; DBMS_OUTPUT.PUT_LINE(STATUS_VALUE); END; / exit; EOF` echo "Return Value... (2 Replies)
Discussion started by: sainathdeg
2 Replies

7. UNIX for Advanced & Expert Users

urgent help needed!!in copying files to /tmp at boot time,pls help!

Hi all, I am trying to boot a an OS from RAM...(its a opensolaris based distro) For this i have picked up 2 key lib files that when copied to /tmp and mounted to respective places will do the job.. The sizes of these files combined comes upto 600mb.(i have 2gb ram) Now i have also located the... (0 Replies)
Discussion started by: wrapster
0 Replies

8. Shell Programming and Scripting

Comparing two txt files - pls help

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... (5 Replies)
Discussion started by: jisha
5 Replies

9. Shell Programming and Scripting

Pls Help.. Really Urgent

Hi, I am creating a pipe in a directory $HOME/pipes. The pipename should be L${PROGNAME}. Whenever i embed these lines in shell script, i get an error mkfifo: No such file or directory. I am creating a pipe with the key word mkfifo $HOME/pipes/L${PROGNAME}. Please help me how to get... (5 Replies)
Discussion started by: raghavan.aero
5 Replies

10. Shell Programming and Scripting

Please Help (Urgent) - Comparing 2 files with "awk"

Hi, I would be grateful for any assistance in my situation. As a new comer to UNIX, I have tried, but in vain, to search for scripts or methods for this problem. I need to compare 2 files. A field in the master is to be tested for a match in the slave. Once a match is found, a variable stated... (10 Replies)
Discussion started by: zom_chp
10 Replies
Login or Register to Ask a Question