Sponsored Content
Top Forums UNIX for Beginners Questions & Answers awk code to find difference in second file which is not present in first file . Post 303040041 by RudiC on Tuesday 22nd of October 2019 09:06:36 AM
Old 10-22-2019
Your files are NOT *nix text files - they use DOS <CR> (= ^M = 0x0D = \r) line terminators, which usually cause problems with *nix text tools:
Code:
file /tmp/file*
/tmp/file1.txt:  ASCII text, with CRLF line terminators
/tmp/file2.txt:  ASCII text, with CRLF line terminators


On top, file2.txt doesn't have a terminating line feed mandatory for *nix text files.

Trying to reproduce your output, I get
Code:
awk ' NR==FNR { a[$0]; next } !($0 in a)' /tmp/file2.txt /tmp/file1.txt
/proc                 -         -         -    - /proc
/dev/hd05opt       2.50      1.37      0.13   92% /opt
abcdef:/ghi/ABC/NIK 349479.97 211239.03 138240.94   61% /mpc

, which, after adding the terminating line feed in file2, reduces to
Code:
/proc                 -         -         -    - /proc
/dev/hd05opt       2.50      1.37      0.13   92% /opt


BTW, diff might be the tool of choice for this case:
Code:
diff /tmp/file1.txt /tmp/file2.txt
7,8d6
< /proc                 -         -         -    - /proc
< /dev/hd05opt       2.50      1.37      0.13   92% /opt
16c14
< abcdef:/ghi/ABC/NIK 349479.97 211239.03 138240.94   61% /mpc
---
> abcdef:/ghi/ABC/NIK 349479.97 211239.03 138240.94   61% /mpc
\ No newline at end of file

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To find the count of records from tables present inside a file.

hi gurus, I am having a file containing a list of tables.i want to find the count of records inside thes tables. for this i have to connect into database and i have to put the count for all the tables inside another file i used the following loop once all the tablenames are inside the file. ... (1 Reply)
Discussion started by: navojit dutta
1 Replies

2. Shell Programming and Scripting

Script to find all the files that contain any of the words present in another file

Hi All, I am new to UNIX and shell scripts and also new to this forum. I need a script to find all the files in a directory that contain any of the strings present in another file. Please provide me the script or if you could provide pointers to any link in this forum it would be helpful.... (4 Replies)
Discussion started by: tsanthosh
4 Replies

3. Shell Programming and Scripting

find difference in file column...

Hi All, i have a file that is tab delimited. i need help to find the rows which are having same price based on the site code but some times, there are difference so i need to find only the records which are different in all site code. Dept Sec Barcode 10001 10002 10003 10004... (1 Reply)
Discussion started by: malcomex999
1 Replies

4. Shell Programming and Scripting

Find file size difference in two files using awk

Hi, Could anyone help me to solve this problem? I have two files "f1" and "f2" having 2 fields in each, a) file size and b) file name. The data are almost same in both the files except for few and new additional lines. Now, I have to find out and print the output as, the difference in the... (3 Replies)
Discussion started by: royalibrahim
3 Replies

5. UNIX for Dummies Questions & Answers

How to find a string that is present in the file or not?

Im pretty new to shell scripting, but i have got the jist of it over the past 10 weeks or so i have been using it. I just have one thing im stuck on thats bugging the hell out of me. Here it goes... I need a script that - You enter a filename and then a string which reports whether that string... (2 Replies)
Discussion started by: Waggie14
2 Replies

6. Shell Programming and Scripting

Speed : awk command to count the occurrences of fields from one file present in the other file

Hi, file1.txt AAA BBB CCC DDD file2.txt abc|AAA|AAAabcbcs|fnwufnq bca|nwruqf|AAA|fwfwwefwef fmimwe|BBB|fnqwufw|wufbqw wcdbi|CCC|wefnwin|wfwwf DDD|wabvfav|wqef|fwbwqfwfe i need the count of rows of file1.txt present in the file2.txt required output: AAA 2 (10 Replies)
Discussion started by: mdkm
10 Replies

7. UNIX for Dummies Questions & Answers

Find the timestamp difference between two different colums in a file

Sample Input File 2014/10/09 CDE876172588765 00:09:45 00:10:10 200 200 11.7093 2014/10/09 CDE366134588757 01:04:34 01:04:54 210 210 9.8898 2014/10/09 CDE765172345745 03:05:46 03:06:01 100 100 10.0601 2014/10/09 ... (8 Replies)
Discussion started by: rpm120
8 Replies

8. UNIX for Beginners Questions & Answers

UNIX utility to find difference in folder, file and contents of file against a base version

Hi, I am trying to find out whether there are any Unix utilities that compares folders, files and contents within the file and provides a comprehensive report. The comparison can be against base version of a folder and file with content. Can you please let me know of such a utility? Thanks,... (6 Replies)
Discussion started by: Sripathi_ks
6 Replies

9. Shell Programming and Scripting

Systemd errors of missing file “No such file or directory” inspite of file being present

The contents of my service file srvtemplate-data-i4-s1.conf is Description=test service for users After=network.target local-fs.target Type=forking RemainAfterExit=no PIDFile=/data/i4/srvt.pid LimitCORE=infinity EnvironmentFile=%I . . . WantedBy=multi-user.target (0 Replies)
Discussion started by: rupeshkp728
0 Replies

10. Shell Programming and Scripting

Compare 2 files and extract the data which is present in other file - awk is not working

file2 content f1file2 content f1,1,2,3,4,5 f1,2,4,6,8,10 f10,1,2,3,4,5 f10,2,4,6,8,10 f5,1,2,3,4,5 f5,2,4,6,8,10awk 'FNR==NR{a;next}; !($1 in a)' file2 file1output f10,1,2,3,4,5 f10,2,4,6,8,10 f5,1,2,3,4,5 f5,2,4,6,8,10awk 'FNR==NR{a;next}; ($1 in a)' file2 file1output nothing... (4 Replies)
Discussion started by: gksenthilkumar
4 Replies
ZDIFF(1)						    BSD General Commands Manual 						  ZDIFF(1)

NAME
zcmp, zdiff -- compare compressed files SYNOPSIS
zcmp [options] file [file2] zdiff [options] file [file2] DESCRIPTION
zcmp and zdiff are filters that invoke cmp(1) or diff(1) respectively to compare compressed files. Any options that are specified are passed to cmp(1) or diff(1). If only file1 is specified, it is compared against a file with the same name, but with the extension removed. When both file1 or file2 are specified, either file may be compressed. Extensions handled by gzip(1): o z, Z, o gz, o taz, o tgz. Extensions handled by bzip2(1): o bz, o bz2, o tbz, o tbz2. Extensions handled by xz(1): o lzma, o xz, o tlz, o txz. ENVIRONMENT
TMPDIR Directory in which to place temporary files. If unset, /tmp is used. FILES
/tmp/zcmp.XXXXXXXXXX Temporary file for zcmp. /tmp/zdiff.XXXXXXXXXX Temporary file for zdiff. SEE ALSO
bzip2(1), cmp(1), diff(1), gzip(1), xz(1) CAVEATS
zcmp and zdiff rely solely on the file extension to determine what is, or is not, a compressed file. Consequently, the following are not supported as arguments: - directories - device special files - filenames indicating the standard input (``-'') BSD
May 23, 2011 BSD
All times are GMT -4. The time now is 04:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy