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
# 8  
Old 08-17-2017
Apologies for the delayed response. Didn't realize wisecracker responded.

Yes wisecracker, when I first posted my query, all the files were in the current directory. The 3 steps process of first sorting the 2 files and saving into other files, followed by applying "comm" command on the sorted files succeeded.

I tried all the commands again, this time the "comm" also worked. I was puzzled how it worked this time.

My guess is when I first posted my query, as RudiC pointed I didn't apply "process substitution"; later when I did, I guess someone else removed those files from my current directory during that time that I didn't realize.

Please see below:
Code:
$ ls -ltr
total 134808
-rw-r--r-- 1 xbbldyx y8dxmr     14008 Aug 16 23:36 file_old
-rw-r--r-- 1 xbbldyx y8dxmr     15033 Aug 16 23:37 file_new
..
..
$ comm -3 < sort file_old < sort file_new > new_file
-ksh: sort: cannot open [No such file or directory]
$ comm -3 <sort file_old <sort file_new > new_file
-ksh: sort: cannot open [No such file or directory]
$ comm -3 <(sort file_old) <(sort file_new) > new_file
$ more new_file
        ||G6||||Y||||1000|5000|6/4/2008|||3||6/16/2166|1010|xyz|Y||||FR|FR|FR|0.014|JR|GEN||||N|FR||8.0|USD||1
$ diff file_old file_new
10a11
>||G6||||Y||||1000|5000|6/4/2008|||3||6/16/2166|1010|xyz|Y||||FR|FR|FR|0.014|JR|GEN||||N|FR||8.0|USD||1

$ sort file_old > file1
$ sort file_new > file2
$ comm -3 file1 file2 > file3
$ diff new_file file3
$

Thank you RudiC for the tip, Don for clarification and wisecracker for prompting me to check if the files exist. Thank you all.

Last edited by Don Cragun; 08-17-2017 at 01:17 AM.. Reason: Edit tags again. Solved is a thread tag, not a text tag. <Code>/</Code> -> [Code]/[/Code].
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