Sponsored Content
Top Forums Shell Programming and Scripting Compare 2 files and print matches and non-matches in separate files Post 302778211 by RudiC on Sunday 10th of March 2013 05:19:32 AM
Old 03-10-2013
For your first request, you might want to give this a shot:
Code:
awk     'NR==1          {Pat = "["}
         NR==FNR        {Pat = Pat $1;next}
         FNR==1         {Pat=Pat"]"}
         {for (i=1; i<=NF; i++)
            if ($i~Pat) print $i > "C"FNR"match.txt"
              else      print $i > "C"FNR"nonmatch.txt" }
        ' file1 file2

This User Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Comparing two files and noting matches

I have two files. One contains names and another file (66 MB, ASCII format) contains details of persons. How do I compare the names in the first file with the second file and write the matches to a third file. I would prefer this to be solved in UNIX or VB. Thanks. (2 Replies)
Discussion started by: augustinep
2 Replies

2. Shell Programming and Scripting

Looking for a string in files and reporting matches

Can someone please help me figure out what the command syntax I need to use is? Here is what I am wanting to do. I have hundreds of thousands of files I need to look for a specific search string in. These files are spread across multiple subdirectories from one main directory. I would like... (4 Replies)
Discussion started by: btrotter
4 Replies

3. Shell Programming and Scripting

looking for files and modify if size matches

hi there. I'm at SunOS 5.9 At my new job i'm using UNIX, and it's my first time. i'm trying to make a script for: -find files with a name passed to it as parameter -compare results with file size passed as parameter too -when comparison's true --> move file -if not--> make nothing ... (3 Replies)
Discussion started by: viko
3 Replies

4. Shell Programming and Scripting

Joining columns from two files, if the key matches

I am trying to join/paste columns from two files for the rows with matching first field. Any help will be appreciated. Files can not be sorted and may not have all rows in both files. Thanks. File1 aaa 111 bbb 222 ccc 333 File2 aaa sss mmmm ccc kkkk llll ddd xxx yyy Want to... (1 Reply)
Discussion started by: sk_sd
1 Replies

5. Shell Programming and Scripting

If string matches within 2 files, delete one file.

I have a directory with a large # of files and in each file I am looking to match a string in one file with a string in the subsequent n file(s). If there is a match between a string in one file and a string in the next n file(s) then delete the subsequent duplicate file(s). Here is sample input: ... (2 Replies)
Discussion started by: sitney
2 Replies

6. Shell Programming and Scripting

Comparing the matches in two files using awk when both files have their own field separators

I've two files with data like below: file1.txt: AAA,Apples,123 BBB,Bananas,124 CCC,Carrot,125 file2.txt: Store1|AAA|123|11 Store2|BBB|124|23 Store3|CCC|125|57 Store4|DDD|126|38 So,the field separator in file1.txt is a comma and in file2.txt,it is | Now,the output should be... (2 Replies)
Discussion started by: asyed
2 Replies

7. Shell Programming and Scripting

Compare two text files and print matches

Hi, I am looking for a way to compare two text files and print the matches. For example; File1.txt 89473036 78474384 48948408 95754748 47849030 File2.txt 47849030 46730356 16734947 78474384 36340047 Output: (11 Replies)
Discussion started by: lewk
11 Replies

8. Shell Programming and Scripting

Merge two columns from two files into one if another column matches

I have two text files that look something like this: A:B:C 123 D:E:F 234 G:H:I 345 J:K:L 123 M:N:O 456 P:Q:R 567 A:B:C 456 D:E:F 567 G:H:I 678 J:K:L 456 M:N:O 789 P:Q:R 890 I want to find the line where the first column matches and then combine the second columns into a single... (8 Replies)
Discussion started by: pbluescript
8 Replies

9. UNIX for Dummies Questions & Answers

Print only '+' or '-' if string matches (two files)

I would like to add two additional conditions to the actual code I have: print '+' if in File2 field 5 is greater than 35 and also field 7 is grater than 90. while read -r line do grep -q "$line" File2.txt && echo "$line +" || echo "$line -" done < File1.txt ' Input file 1: ... (5 Replies)
Discussion started by: bernardo.bello
5 Replies

10. Shell Programming and Scripting

BASH - Compare 2 Files, Output All Matches

This is probably rehash but I did look. :rolleyes: I want a bash script that will take Item 1 in File1, traverse all lines in File2 and output if a match exists. Continuing the pattern recursively, Item2, File1, traverse all lines in File2 for a match, continue this pattern until all lines... (6 Replies)
Discussion started by: rcbarr2014
6 Replies
crc16(n)						     Cyclic Redundancy Checks							  crc16(n)

__________________________________________________________________________________________________________________________________________________

NAME
crc16 - Perform a 16bit Cyclic Redundancy Check SYNOPSIS
package require Tcl 8.2 package require crc16 ?1.1.1? ::crc::crc16 ?-format format? ?-seed value? ?-implementation procname? message ::crc::crc16 ?-format format? ?-seed value? ?-implementation procname? -filename file ::crc::crc-ccitt ?-format format? ?-seed value? ?-implementation procname? message ::crc::crc-ccitt ?-format format? ?-seed value? ?-implementation procname? -filename file ::crc::xmodem ?-format format? ?-seed value? ?-implementation procname? message ::crc::xmodem ?-format format? ?-seed value? ?-implementation procname? -filename file _________________________________________________________________ DESCRIPTION
This package provides a Tcl-only implementation of the CRC algorithms based upon information provided at http://www.microconsul- tants.com/tips/crc/crc.txt There are a number of permutations available for calculating CRC checksums and this package can handle all of them. Defaults are set up for the most common cases. COMMANDS
::crc::crc16 ?-format format? ?-seed value? ?-implementation procname? message ::crc::crc16 ?-format format? ?-seed value? ?-implementation procname? -filename file ::crc::crc-ccitt ?-format format? ?-seed value? ?-implementation procname? message ::crc::crc-ccitt ?-format format? ?-seed value? ?-implementation procname? -filename file ::crc::xmodem ?-format format? ?-seed value? ?-implementation procname? message ::crc::xmodem ?-format format? ?-seed value? ?-implementation procname? -filename file The command takes either string data or a file name and returns a checksum value calculated using the CRC algorithm. The command used sets up the CRC polynomial, initial value and bit ordering for the desired standard checksum calculation. The result is format- ted using the format(n) specifier provided or as an unsigned integer (%u) by default. A number of common polynomials are in use with the CRC algorithm and the most commonly used of these are included in this package. For convenience each of these has a command alias in the crc namespace. It is possible to implement the CRC-32 checksum using this crc16 package as the implementation is sufficiently generic to extend to 32 bit checksums. As an example this has been done already - however this is not the fastest method to implement this algorithm in Tcl and a separate crc32 package is available. OPTIONS
-filename name Return a checksum for the file contents instead of for parameter data. -format string Return the checksum using an alternative format template. -seed value Select an alternative seed value for the CRC calculation. The default is 0 for the CRC16 calculation and 0xFFFF for the CCITT ver- sion. This can be useful for calculating the CRC for data structures without first converting the whole structure into a string. The CRC of the previous member can be used as the seed for calculating the CRC of the next member. It is also used for accumulating a checksum from fragments of a large message (or file) -implementation procname This hook is provided to allow users to provide their own implementation (perhaps a C compiled extension). The procedure specfied is called with two parameters. The first is the data to be checksummed and the second is the seed value. An integer is expected as the result. The package provides some implementations of standard CRC polynomials for the XMODEM, CCITT and the usual CRC-16 checksum. For con- venience, additional commands have been provided that make use of these implementations. EXAMPLES
% crc::crc16 "Hello, World!" 64077 % crc::crc-ccitt "Hello, World!" 26586 % crc::crc16 -format 0x%X "Hello, World!" 0xFA4D % crc::crc16 -file crc16.tcl 51675 AUTHORS
Pat Thoyts BUGS, IDEAS, FEEDBACK This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category crc of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have for either package and/or documentation. SEE ALSO
cksum(n), crc32(n), sum(n) KEYWORDS
checksum, cksum, crc, crc16, crc32, cyclic redundancy check, data integrity, security CATEGORY
Hashes, checksums, and encryption COPYRIGHT
Copyright (c) 2002, Pat Thoyts crc 1.1.1 crc16(n)
All times are GMT -4. The time now is 03:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy