comm command -- Sort and compare two files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting comm command -- Sort and compare two files
# 1  
Old 03-19-2012
comm command -- Sort and compare two files

Team,

I have two files and I am trying to find the lines unique to file1. So i have executed the below command at shell prompt and got the correct results
Code:
 
comm -23 <(sort test) <(sort test1)

When i run the same command in Bash shell script, i got the correct results.
But when i run the same command in Korn shell script, i am getting syntax error.

Error: syntax error: `(' unexpected

Can you let me know the the correct syntax in Korn Shell or is there any way to execute the command alone in bash shell and the rest of the script in Korn.
# 2  
Old 03-19-2012
Works for me even on a fairly old version of Kshell (Version JM 93t+ 2009-02-02). What version of ksh do you have?

You can run echo "${.sh.version}" or ksh --version at the command line to show the version.
# 3  
Old 03-19-2012
I tried below three commands. None returned the verion. Output of $KSH_VERSION is blank

Code:
ksh --version

ksh: ksh: --: unknown option

Code:
echo "${.sh.version}"

bash: ${.sh.version}: bad substitution

Code:
echo $KSH_VERSION

# 4  
Old 03-19-2012
How about uname -a
# 5  
Old 03-19-2012
And rather than executing the echo from a bash prompt, try this:

Code:
ksh -c "echo ${.sh.version}"

This User Gave Thanks to agama For This Post:
# 6  
Old 03-19-2012
Try the old way:
Code:
sort <test >test.sor
sort <test1 >test1.sor
#
comm -23  test test1
#
rm test.sor
rm test1.sor

Ps. It is not advisible to call a file the same name as a unix command. In this case "test".


Pps. For an older ksh, the version is displayed by:
Esc K ^V
(Escape K Ctrl/V)

Last edited by methyl; 03-19-2012 at 10:46 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Compare files (not using comm )

i have file1 and file2 file1 ABC XYZ file2 ABC so i used the below command comm -12 file1 file2 > matched comm -23 file1 file2 > unmatched I need some other command because this is not working in the current unix version (1 Reply)
Discussion started by: ATWC
1 Replies

2. Shell Programming and Scripting

How to sort and compare files in more efficient manner?

Hello All, Iam using below method to sort and compare files. First iam doing sorting and changing the same file and then doing comparing and taking the final result to another file. sort -o temp.txt file1 mv temp.txt file1 sort -o temp.txt file2 mv temp.txt file2 sort -o temp.txt... (6 Replies)
Discussion started by: Vikram_Tanwar12
6 Replies

3. UNIX for Dummies Questions & Answers

Need help with comm command

Hello , I am trying to get contents which are only present in a.csv ,so using comm -23 cat a.csv | sort > a.csv cat b.csv | sort > b.csv comm -23 a.csv b.csv > c.csv. a.csv SKU COUNTRY CURRENCY PRICE_LIST_TYPE LIST_PRICE_EFFECTIVE_DATE TG430ZA ZA USD DF ... (4 Replies)
Discussion started by: RaviTej
4 Replies

4. Shell Programming and Scripting

Comm compare, but column specific

I'm looking to compare two delimited files: file1 one|xxx two|xxx three|xxx file2 four|xxx five|xxx six|xxx one|yyy Where the result is the the file2 row whose first field does NOT appear in file1. I.e., the correct result would be: result four|xxx (3 Replies)
Discussion started by: tiggyboo
3 Replies

5. Shell Programming and Scripting

Require compare command to compare 4 files

I have four files, I need to compare these files together. As such i know "sdiff and comm" commands but these commands compare 2 files together. If I use sdiff command then i have to compare each file with other which will increase the codes. Please suggest if you know some commands whcih can... (6 Replies)
Discussion started by: nehashine
6 Replies

6. UNIX for Dummies Questions & Answers

help on COMM command please

could some one please explain with examples how comm -12 & comm -3 works. I am confused with manual page, Thankyou. (2 Replies)
Discussion started by: Ariean
2 Replies

7. UNIX for Dummies Questions & Answers

sort and compare files

Hi, I have around 14-15 files and i want to sort all the files and then compare. I dont want to sort them and store in a different file and then compare. I want to compare two files at a time. Is there a way we can do this using a single command? (5 Replies)
Discussion started by: dnat
5 Replies

8. Shell Programming and Scripting

comm command

Hi I have issue with "comm " command file-1 ---- l65059 l65407 l68607 l68810 l69143 l71310 l72918 l73146 l73273 l76411 file-2 ----- (8 Replies)
Discussion started by: amitrajvarma
8 Replies

9. UNIX for Dummies Questions & Answers

Can you limit the compare on "comm" command

I need to find deleted records from a file. I compare yesterdays file.old to todays file.new. I need to find the records that were in yesterdays file that are not in todays. My file is fixed field. If I run a "comm -23" obviously what i find is not necesarilly a delete, it could be a change. ... (0 Replies)
Discussion started by: eja
0 Replies

10. UNIX for Dummies Questions & Answers

Comm, command help

See my other post on sdiff .... I don't think sdiff is able to do what I want. The 'comm' command does what I need and works fine as far as the logic and results. The problem I'm having is with the output format, it outputs 3 columns of data, but because of the way it starts each line... (2 Replies)
Discussion started by: cowpoke
2 Replies
Login or Register to Ask a Question