Extract delta records using with "comm" and "sort" commands combination


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Extract delta records using with "comm" and "sort" commands combination
# 1  
Old 08-16-2017
Extract delta records using with "comm" and "sort" commands combination

Hi All,
I have 2 pipe delimited files viz., file_old and file_new. I'm trying to compare these 2 files, and extract all the different rows between them into a new_file.

Code:
comm -3 < sort file_old < sort file_new > new_file

I am getting the below error:
Code:
-ksh: sort: cannot open [No such file or directory]

But if I do as below, it is successfully giving me the difference.
Code:
sort file_old > file1
sort file_new > file2
comm -3 file1 file2 > file3

Can you please help me understand why the first approach resulting in an error?

Thank you.

PS: I did search the forum before posting this thread but no luck


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 08-16-2017 at 03:52 PM.. Reason: Added CODE tags.
# 2  
Old 08-16-2017
I think you need to deploy ksh's "process substitution":
Code:
comm -3 <(sort file_old) <(sort file_new) > new_file

# 3  
Old 08-16-2017
It displayed syntax error if I include brackets "()".

Code:
comm -3 < (sort file1) < (sort file3) > file3
-ksh: syntax error: `(' unexpected

comm -3 < (sort file1) < (sort file3) > (file3)
-ksh: syntax error: `(' unexpected


Last edited by Don Cragun; 08-16-2017 at 04:22 PM.. Reason: Fix CODE tags (<CODE>,</CODE> -> [CODE],[/CODE].
# 4  
Old 08-16-2017
That's NOT what I posted!
# 5  
Old 08-16-2017
To expand a little bit on what RudiC already said...

If you're trying to perform process substitution, there can't be any space between the redirection operator and the (utility [argument...]).

To avoid confusion in the future, note that ( and ) are called parentheses; brackets are [ and ] and braces are { and }. Brackets, braces, and parentheses all have distinct meaning in the shell command language; they are not interchangeable.

Note also that process substitution is a fairly new feature in ksh and is not available in all versions of the Korn shell. And, you haven't told us which version of ksh you're using. It was not available in any version of ksh before 1993 and was not in the early version of ksh93. It is in version 93u+ from August 1, 2012, but I am not sure which version first included process substitution.
# 6  
Old 08-16-2017
Thank you Don for explaining in so much detail. Please see below, getting same error even after removing the spaces between "<"/">" and following command.

Code:
$ ksh --v
  version         sh (AT&T Research) 93u+ 2012-08-01
$ comm -3 <sort file_old <sort file_new >new_file
-ksh: sort: cannot open [No such file or directory]

---------- Post updated at 04:19 PM ---------- Previous update was at 04:16 PM ----------

It didn't work with parenthesis also.

Code:
$ comm -3 <(sort file_old) <(sort file_new) >new_file
-ksh: sort: cannot open [No such file or directory]


Last edited by Don Cragun; 08-16-2017 at 07:46 PM.. Reason: Fix CODE tags again: <CODE>/</CODE> -> [CODE]/[/CODE]
# 7  
Old 08-16-2017
Quote:
Originally Posted by njny
<Code>
$ comm -3 <(sort file_old) <(sort file_new) >new_file
-ksh: sort: cannot open [No such file or directory]
</Code>
Are you pointing to the correct directory?
Does that directory exist?
Are 'file_old' and 'file_new' in the current directory?
Do both in fact exist?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

AWK for multiple line records RS="^" FS="#"

I have to pull multiple line records with ^ as the record separator(RS)... # should be my field separator (FS)... Sample record is: ^-60#ORA-00060: deadlock detected while waiting for resource ORA-00001: unique constraint (SARADM.TCKNUM_PK) violated#PROC:AVAILABLE_FOR_GETNXTTIC#02/27/2012... (7 Replies)
Discussion started by: Vidhyaprakash
7 Replies

5. Red Hat

files having Script which works behind "who" & "w" commands

Dear All, plz print the path of files which have the script of "who" & "w" commands. thnx in advance. (6 Replies)
Discussion started by: saqlain.bashir
6 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

Unix commands delete all files starting with "X" except "X" itself. HELP!!!!?

im a new student in programming and im stuck on this question so please please HELP ME. thanks. the question is this: enter a command to delete all files that have filenames starting with labtest, except labtest itself (delete all files startign with 'labtest' followed by one or more... (2 Replies)
Discussion started by: soccerball
2 Replies

8. Shell Programming and Scripting

catalina.sh : need combination from "start" and "run"

heya, can someone help me with following problem. i am not sure how far you know the catalina.sh script from tomcat. when i start my tomcat with "catalina.sh run" then the startup-process-output will be printed out on the console, but the tomcat process is started in current shell/session, so... (1 Reply)
Discussion started by: Filly
1 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question