Script to compare 1 file with all others


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to compare 1 file with all others
# 1  
Old 12-22-2011
Script to compare 1 file with all others

I need a script to compare 1 file with all others then print off any new lines which the other files do not have.

Running:

Solaris 10 5/09 s10s_u7wos_08 SPARC

Any help or pointers would be appreciated
# 2  
Old 12-22-2011
Try:
Code:
for i in *; do comm -23 <(sort file_1) <(sort $i); done

Didn't test it.
This User Gave Thanks to bartus11 For This Post:
# 3  
Old 12-22-2011
Quote:
Originally Posted by bartus11
Try:
Code:
for i in *; do comm -23 <(sort file_1) <(sort $i); done

Didn't test it.
can you explain what each bit does? as I'm not quite there yet
# 4  
Old 12-22-2011
First tell if it worked for you Smilie
# 5  
Old 12-22-2011
I used
Code:
for i in *; do comm -23 <(sort 20111222.csv) <(sort $*csv); done

but it seemed to print everything off?

I need it to compare 20111222.csv with *csv then print off only new lines..

Smilie

---------- Post updated at 12:12 AM ---------- Previous update was at 12:02 AM ----------

say the files typically have lines like so:
Code:
NE:220036,SHELF:1,SLOT:4,19:30:02,Thu Dec 22 2011
NE:223334,SHELF:9,SLOT:5,19:30:02,Thu Dec 22 2011
NE:877351,SHELF:2,SLOT:6,21:00:01,Thu Dec 22 2011
NE:222544,SHELF:2,SLOT:1,22:30:01,Thu Dec 22 2011

I need it to compare only NE:222544,SHELF:2,SLOT:1 from one file against all others to see if there is a match or not, if there isn't print it off as a new line, the ,22:30:01,Thu Dec 22 2011 bit i want it to not compare but ignore

sorry

Last edited by Franklin52; 12-23-2011 at 03:51 AM.. Reason: Please use code tags for code and data samples, thank you
# 6  
Old 12-22-2011
Try this...
Code:
awk -F, 'NR==FNR{a[$1$2$3]++;next} !a[$1$2$3]' 20111222.csv *.csv

--ahamed
This User Gave Thanks to ahamed101 For This Post:
# 7  
Old 12-22-2011
Quote:
Originally Posted by ahamed101
Try this...
Code:
awk -F, 'NR==FNR{a[$1$2$3]++;next} !a[$1$2$3]' 20111222.csv *.csv

--ahamed

tried that this is the output


Code:
#awk -F, 'NR==FNR{a[$1$2$3]++;next} !a[$1$2$3]' 20111223.csv *.csv
awk: syntax error near line 1
awk: bailing out near line 1


Last edited by Franklin52; 12-23-2011 at 05:34 PM.. Reason: Please use code tags for data and code samples, thank you
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with file compare and move script

I'm running debian (the raspbian version of it) and working on a script to compare files in 2 directories, source and target, move files with duplicate names to a 3rd directory, then move remaining files in source to target. I can't get the syntax right, keep getting syntax errors and can't get... (7 Replies)
Discussion started by: mattz40
7 Replies

2. Shell Programming and Scripting

Shell script (sh file) logic to compare contents of one file with another file and output to file

Shell script logic Hi I have 2 input files like with file 1 content as (file1) "BRGTEST-242" a.txt "BRGTEST-240" a.txt "BRGTEST-219" e.txt File 2 contents as fle(2) "BRGTEST-244" a.txt "BRGTEST-244" b.txt "BRGTEST-231" c.txt "BRGTEST-231" d.txt "BRGTEST-221" e.txt I want to get... (22 Replies)
Discussion started by: pottic
22 Replies

3. Shell Programming and Scripting

Bash script to compare 2 file

Hello Friends please help me to create script to compare 2 fiile which has rpm info . File 1: glibc-2.12.1.149.el6_6.5.x86_64.rpm glibc-common-2.12-1.149.el6_6.5.x86_64.rpm File 2 : glibc-2.12.123.el6_6.5.x86_64.rpm glibc-common-2.12-123.el6_6.5.x86_64.rpm To compare file1... (1 Reply)
Discussion started by: rnary
1 Replies

4. Shell Programming and Scripting

Script to compare lines in a file

Need help to create the script that does the following : - 1. Compare the current line "column B and C" with next line "column B and C" 2. If they are the same, print output to a file Input file 2014-08-25 04:45:56.673|T1|JO|Begin|10 2014-08-25 04:55:56.673|T1|JO|Begin|11 2014-08-25... (8 Replies)
Discussion started by: chailee
8 Replies

5. Shell Programming and Scripting

script to grep a pattern from file compare contents with another file and replace

Hi All, Need help on this I have 2 files one file file1 which has several entries as : define service{ hostgroup_name !host1,!host5,!host6,.* service_description check_nrpe } define service{ hostgroup_name !host2,!host4,!host6,.* service_description check_opt } another... (2 Replies)
Discussion started by: namitai
2 Replies

6. Shell Programming and Scripting

script to compare two columns in a file

Dear everyone, I need any sort of shell script or perl script would do the following. I have a txt file as follows: ;Stretnumber Resident Resdient (not in file) 16 John Mary 16 Mary Parker 16 Nancy Smith 16 Mary John 18 Trey ... (5 Replies)
Discussion started by: sasharma
5 Replies

7. Shell Programming and Scripting

Script to compare file sizes

I need to write a bash script larger X Y that compares the sizes of two specified files X and Y, and reports which file is larger. For example, if X is larger, the output should be "File X is larger", while if Y is larger, the output should be "File Y is larger". If the files are exactly the... (3 Replies)
Discussion started by: julia_21436
3 Replies

8. Shell Programming and Scripting

Unix script to compare the two file

Hi, I want to compare two | delimited files.Awk is not working in my unix box.So plz give alternate solutions. Please see the below code: file1=$1 file2=$2 num_of_records_file1=`awk ' END { print NR } ' $file1` num_of_records_file2=`awk ' END { print NR } ' $file2` i=1 while do... (4 Replies)
Discussion started by: autosys_nm
4 Replies

9. Shell Programming and Scripting

Check File Exists and compare to previous day file script

We have data files that are ftp'd every morning to a SUN server. The file names are exactly the same except for that each has the date included in its name. I have to write script to do 2 things: STEP 1) Verify that the file arrived in morning. STEP 2) Compare the file size of the current... (3 Replies)
Discussion started by: rbknisely
3 Replies

10. Shell Programming and Scripting

compare file size from a output file from a script

Hi guys, firstly I'm working on SunOS 5.10 Generic_125100-10 sun4u sparc SUNW,Sun-Fire-V240 I've made a script to compress two directory and then send them to an other server via ftp. This is working very well. Inside theis script I decide to log usefull data for troubleshooting in case of... (7 Replies)
Discussion started by: moustik
7 Replies
Login or Register to Ask a Question