Sponsored Content
Top Forums Shell Programming and Scripting Using Diff to Compare 2 files Post 302410932 by ladyAnne on Wednesday 7th of April 2010 07:28:29 AM
Old 04-07-2010
Thank you so much. Suppose I wanted to list the line from the old file (the original data) along with what has changed in the second file, hwo can I do that?
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

diff 2 files; output diff's to 3rd file

Hello, I want to compare two files. All records in file 2 that are not in file 1 should be output to file 3. For example: file 1 123 1234 123456 file 2 123 2345 23456 file 3 should have 2345 23456 I have looked at diff, bdiff, cmp, comm, diff3 without any luck! (2 Replies)
Discussion started by: blt123
2 Replies

2. UNIX for Dummies Questions & Answers

Compare/Diff between directories and subdirectories?

Hi, Does anybody know the cmd to compare two areas and print out the different files w/ path? I tried cmp and diff and dircmp but with no luck. Should I grep and print? For example: /aa/images/jan ..../images/feb /bb/images/jan ..../images/feb i want to print the compare,... (5 Replies)
Discussion started by: andylee80
5 Replies

3. Shell Programming and Scripting

compare 2 coloum of 2 diff files using perl script

Hi, i am new to perl scripting.. i am still learing it.. i am asked to write a perl script which should compare 2 coloums of 2 different files. if those 2 coloumn are same the script should store the both the lines in 2 diff files. these are files, file 1: 21767016 226112 char 19136520... (3 Replies)
Discussion started by: vasuki
3 Replies

4. Shell Programming and Scripting

Compare two files and output diff to third file

I have made several attempts to read two files of ip addresses and eliminate records from file1 that are in file2. My latest attempt follows. Everything works except my file3 is exactly the same as file1 and it should not be. # !/usr/bin/bash # # NoInterfaces # Utility will create a file... (8 Replies)
Discussion started by: altamaha
8 Replies

5. Shell Programming and Scripting

compare two files, diff the result

Hi Everyone, 1.txt 00:01:01 asdf 00:33:33 1234 00:33:33 0987 00:33:33 12 00:33:33 444 2.txt vvvv|ee 444|dd33|ee dddd|ee 12|ee 3ciur|fdd the output should be: (6 Replies)
Discussion started by: jimmy_y
6 Replies

6. Shell Programming and Scripting

Shell script to compare ,diff and remove betwen 2 files

Hi Friends Need your expertise. Command to check the difference and compare 2 files and remove lines . example File1 is master copy and File2 is a slave copy . whenever i change, add or delete a record in File1 it should update the same in slave copy . Can you guide me how can i accomplish... (3 Replies)
Discussion started by: ajayram_arya
3 Replies

7. Shell Programming and Scripting

Compare two CSV files and put the difference in third file with line no,field no and diff value.

I am having two csv files i need to compare these files and the output file should have the information of the differences at the field level. For Example, File 1: A,B,C,D,E,F 1,2,3,4,5,6 File 2: A,C,B,D,E,F 1,2,4,5,5,6 out put file: (12 Replies)
Discussion started by: karingulanagara
12 Replies

8. Shell Programming and Scripting

Using Diff to compare 2 arrays

I have two arrays and they look like this: array=(`cat /local/mnt/*sys/*includes|grep -v NEW`) array2=(`cat /tmp/*sys.z |grep -v NEW`) I am trying to compare them but I need to use the diff -u command. I am not sure how to do this. I cannot just do diff -u ${array} ${array2} I cannot... (4 Replies)
Discussion started by: newbie2010
4 Replies

9. Shell Programming and Scripting

Diff 3 files, but diff only their 2nd column

Guys i have 3 files, but i want to compare and diff only the 2nd column path=`/home/whois/doms` for i in `cat domain.tx` do whois $i| sed -n '/Registry Registrant ID:/,/Registrant Email:/p' > $path/$i.registrant whois $i| sed -n '/Registry Admin ID:/,/Admin Email:/p' > $path/$i.admin... (10 Replies)
Discussion started by: kenshinhimura
10 Replies
Syntax::Keyword::Gather(3pm)				User Contributed Perl Documentation			      Syntax::Keyword::Gather(3pm)

NAME
Syntax::Keyword::Gather - Provide a gather keyword VERSION
version 1.001000 SYNOPSIS
use Syntax::Keyword::Gather; my @list = gather { # Try to extract odd numbers and odd number names... for (@data) { if (/(one|three|five|seven|nine)$/) { take qq{'$_'} } elsif (/^d+$/ && $_ %2) { take $_ } } # But use the default set if there aren't any of either... take @defaults unless gathered; } or to use the stuff that Sub::Exporter gives us, try # this is a silly idea use syntax gather => { gather => { -as => 'bake' }, take => { -as => 'cake' }, }; my @vals = bake { cake (1...10) }; DESCRIPTION
Perl 6 provides a new control structure -- "gather" -- that allows lists to be constructed procedurally, without the need for a temporary variable. Within the block/closure controlled by a "gather" any call to "take" pushes that call's argument list to an implicitly created array. "take" returns the number of elements it took. This module implements that control structure. At the end of the block's execution, the "gather" returns the list of values stored in the array (in a list context) or a reference to the array (in a scalar context). For example, instead of writing: print do { my @wanted; while (my $line = <>) { push @wanted, $line if $line =~ /D/; push @wanted, -$line if some_other_condition($line); } push @wanted, 'EOF'; join q{, }, @wanted; }; instead we can write: print join q{, }, gather { while (my $line = <>) { take $line if $line =~ /D/; take -$line if some_other_condition($line); } take 'EOF'; } and instead of: my $text = do { my $string; while (<>) { next if /^#|^s*$/; last if /^__[DATA|END]__ $/; $string .= $_; } $string; }; we could write: my $text = join q{}, gather { while (<>) { next if /^#|^s*$/; last if /^__[DATA|END]__ $/; take $_; } }; There is also a third function -- "gathered" -- which returns a reference to the implicit array being gathered. This is useful for handling defaults: my @odds = gather { for @data { take $_ if $_ % 2; take to_num($_) if /[one|three|five|nine]$/; } take (1,3,5,7,9) unless gathered; } Note that -- as the example above implies -- the "gathered" function returns a special Perl 5 array reference that acts like a Perl 6 array reference in boolean, numeric, and string contexts. It's also handy for creating the implicit array by some process more complex than by simple sequential pushing. For example, if we needed to prepend a count of non-numeric items: my @odds = gather { for @data { take $_ if $_ %2; take to_num($_) if /[one|three|five|seven|nine]$/; } unshift gathered, +grep(/[a-z]/i, @data); } Conceptually "gather"/"take" is the generalized form from which both "map" and "grep" derive. That is, we could implement those two functions as: sub map (&@) { my $coderef = shift; my @list = @{shift @_}; return gather { take $coderef->($_) for (@list) }; } sub grep (&@) { my $coderef = shift; my @list = @{shift @_}; return gather { take $_ if $coderef->($_) for @list }; } A "gather" is also a very handy way of short-circuiting the construction of a list. For example, suppose we wanted to generate a single sorted list of lines from two sorted files, but only up to the first line they have in common. We could gather the lines like this: my @merged_diff = gather { my $a = <$fh_a>; my $b = <$fh_b>; while(1) { if ( defined $a && defined $b ) { if ($a eq $b) { last } # Duplicate means end of list elsif ($a lt $b) { take $a; $a = <$fh_a>; } else { take $b; $b = <$fh_b>; } } elsif (defined $a) { take $a; $a = <$fh_a>; } elsif (defined $b) { take $b; $b = <$fh_b>; } else { last } } } NAME
Syntax::Keyword::Gather - Implements the Perl 6 'gather/take' control structure in Perl 5 HISTORY
This module was forked from Damian Conway's Perl6::Gather for a few reasons. to avoid the slightly incendiary name =item to avoid the use of the Perl6::Exporter =item ~ doesn't overload to mean string context =item to no longer takes the current topic ($_) The last item is actually due to an unintended side-effect of the fact that if "take" has an array of zero length it takes $_, which is suprising at the very least. I'll fix that issue if I can. BUGS AND IRRITATIONS
It would be nice to be able to code the default case as: my @odds = gather { for (@data) { take if $_ % 2; take to_num($_) if /(?:one|three|five|nine)z/; } } or (1,3,5,7,9); but Perl 5's "or" imposes a scalar context on its left argument. This is arguably a bug and definitely an irritation. AUTHORS
o Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com> o Damian Conway COPYRIGHT AND LICENSE
This software is copyright (c) 2010 by Arthur Axel "fREW" Schmidt. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.10.1 2011-02-25 Syntax::Keyword::Gather(3pm)
All times are GMT -4. The time now is 05:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy