Sponsored Content
Top Forums Shell Programming and Scripting comparing 2 files and creating third file with uncommon content Post 302598323 by birei on Tuesday 14th of February 2012 05:13:04 AM
Old 02-14-2012
Try:
Code:
$ cat file1
ajay suhas tom nisha vijay mahish
ajay suhas tom nisha vijay mahish
ajay suhas tom nisha vijay mahish
ajay suhas tom nisha vijay mahish
$ cat file2
ajay suhas tom nisha
ajay suhas tom
tom
tom nisha
$ cat script.pl
use warnings;
no strict qw(refs);

die qq[Usage: perl $0 <file1> <file2>\n] unless @ARGV == 2;

open my $fh1, qq[<], shift or die qq[Cannot open input file: $!\n];
open my $fh2, qq[<], shift or die qq[Cannot open input file: $!\n];

while ( my $l1 = <$fh1>, my $l2 = <$fh2> ) {
        chomp( $l1, $l2 );
        my %h1 = map { $_ => 1 } split /\s+/, $l1;
        delete @h1{ split( /\s+/, $l2 ) };
        printf qq[%s\n], join qq[ ], keys %h1;
}
$ perl script.pl file1 file2
vijay mahish
vijay mahish nisha
suhas vijay mahish nisha ajay
suhas vijay mahish ajay

Regards,
Birei
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Creating a tabulated file from content of 2 or more files

Hi all I need specific fields from a file to be tabulated into a single file. I have a file with the following :- FIELD1 InfoA FIELD2 InfoB FILED3 InfoC FIELD1 InfoD FIELD2 InfoE FIELD3 InfoF The output... (2 Replies)
Discussion started by: jhansrod
2 Replies

2. Shell Programming and Scripting

comparing file content differences

I need to write a script to find out if there are any .c files created/removed from the last time i monitored the files available. i first created a file to contain all the .c files available on the system. (ls *.c > file1) I created another file using the same command. I used the comm file1... (4 Replies)
Discussion started by: RianTan
4 Replies

3. Shell Programming and Scripting

comparing files content

hi i have a set of files , i need to compare one file content with other file content, i am using cmp -s abc.1 def.2 , but it is not giving theproper o/p even if the content is different.Please help thanks Satya (1 Reply)
Discussion started by: Satyak
1 Replies

4. Shell Programming and Scripting

Comparing 2 csv files and matching content

Hello, I have the following problem: There are two csv files csv-file #1: aaa1, aaa2, ... aaan aaa1, bbb2, ... bbbn aaa1, ccc2, ... cccn bbb1, bbb2, ... bbbn ... zzz1, zzz2, ... zzzn csv-file #2: aaa1, matchvalue1 ccc1, matchvalue2 (7 Replies)
Discussion started by: ghl10000
7 Replies

5. UNIX for Dummies Questions & Answers

UNcommon lines between files

I have two files, file1.txt and file2.txt I want to find UNcommon between two files with while read line do grep -v $line file2.txt done<file1.txt I get the reverse grep for every line it reads (7 Replies)
Discussion started by: FelipeAd
7 Replies

6. UNIX for Dummies Questions & Answers

creating text file with content from script

hi, can somebody tell me how I can create a text file with content from Bash script. The file should be prefilled with information such as current date and time then leaving the user ability to input more data right below those prefilled content. thank you :) (0 Replies)
Discussion started by: s3270226
0 Replies

7. Shell Programming and Scripting

Comparing two files and creating a new file

Hi, I want to compare two files based on the data in their first column. Both the files are not equal in their number of columns and number of entries or rows. The entries (only the first column) of the file1 should be compared with the entries (only the first column) of the file2. If the... (3 Replies)
Discussion started by: begin_shell
3 Replies

8. Shell Programming and Scripting

Comparing file ownership/permission and content of files located on two different servers

Hi All, can some one suggest me a tool to compare file ownership/permission and contents of files located at two different unix servers? Thanks, Pranav (1 Reply)
Discussion started by: Pranav Bhasker
1 Replies

9. Shell Programming and Scripting

From 2 files create 3rd file with uncommon data

Hi All, I have two files. File1 and File2. Want to create another file with all the records of File1 those are not present in File2. Please guide. Thanks in advanced. Anupam (3 Replies)
Discussion started by: Anupam_Halder
3 Replies

10. UNIX for Beginners Questions & Answers

Comparing two files and list the difference with common first line content of both files

I have two file as given below which shows the ACL permissions of each file. I need to compare the source file with target file and list down the difference as specified below in required output. Can someone help me on this ? Source File ************* # file: /local/test_1 # owner: own #... (4 Replies)
Discussion started by: sarathy_a35
4 Replies
XZDIFF(1)							     XZ Utils								 XZDIFF(1)

NAME
xzcmp, xzdiff, lzcmp, lzdiff - compare compressed files SYNOPSIS
xzcmp [cmp_options] file1 [file2] xzdiff [diff_options] file1 [file2] lzcmp [cmp_options] file1 [file2] lzdiff [diff_options] file1 [file2] DESCRIPTION
xzcmp and xzdiff invoke cmp(1) or diff(1) on files compressed with xz(1), lzma(1), gzip(1), bzip2(1), or lzop(1). All options specified are passed directly to cmp(1) or diff(1). If only one file is specified, then the files compared are file1 (which must have a suffix of a supported compression format) and file1 from which the compression format suffix has been stripped. If two files are specified, then they are uncompressed if necessary and fed to cmp(1) or diff(1). The exit status from cmp(1) or diff(1) is preserved. The names lzcmp and lzdiff are provided for backward compatibility with LZMA Utils. SEE ALSO
cmp(1), diff(1), xz(1), gzip(1), bzip2(1), lzop(1), zdiff(1) BUGS
Messages from the cmp(1) or diff(1) programs refer to temporary filenames instead of those specified. Tukaani 2011-03-19 XZDIFF(1)
All times are GMT -4. The time now is 02:45 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy