Compare two file (please help me it's deadly urgent)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Compare two file (please help me it's deadly urgent)
# 8  
Old 11-16-2010
Try...
Code:
awk 'BEGIN{FS=";"}NR==FNR{a[$1]=$2;next}a[$1]<$2||!a[$1]' template source

# 9  
Old 11-17-2010
that does not work properly

I show you what I have and what I need

template
Code:
McAfee AntiSpyware Enterprise Module;8.7.0.130
MySQL ODBC 3.51 Driver;03.51.05 - Gamma
Windows XP Service Pack 3



source
Code:
McAfee AntiSpyware Enterprise Module;8.7.0.129
Windows XP Service Pack 3;20080414.175805
McAfee VirusScan Enterprise
Altiris Version: 6.9.430.0

output must be
Code:
McAfee AntiSpyware Enterprise Module;8.7.0.130
MySQL ODBC 3.51 Driver;03.51.05 - Gamma


McAfee AntiSpyware Enterprise Module;8.7.0.130 - becouse version in source is older
MySQL ODBC 3.51 Driver;03.51.05 - Gamma - becouse it is not in source.
Or any other way, I need just point on mismatch

The way pravin27 supposed is pretty good

Code:
 awk -F"." 'NR==FNR{a[$1]++;next} !a[$1]' source template.txt

But it is not show me mismatch in version, only lines that are not in source
# 10  
Old 11-17-2010
I hope this will solve your problem
Code:
awk -F";" 'NR==FNR{a[$1]=$2;next} !a[$1] ||a[$1] < $2 ' source template.txt

This User Gave Thanks to pravin27 For This Post:
# 11  
Old 11-17-2010
It's work.
How to put this line to file for awk?
I mean i like to use it in pipe and want start this program in bash.
# 12  
Old 11-17-2010
You can create bash script like below

script.sh
Code:
#!/bin/sh
awk -F";" 'NR==FNR{a[$1]=$2;next} !a[$1] ||a[$1] < $2 ' source template.txt

Why you want to use this in pipe bcoz we are processing two input flles
# 13  
Old 11-17-2010
It's not match fo my task.
I want use awk -f program.awk
Is there any way to solve

---------- Post updated at 07:53 AM ---------- Previous update was at 07:51 AM ----------

it's becouse I plan to use script on unix and windows machines

---------- Post updated at 07:54 AM ---------- Previous update was at 07:53 AM ----------

I have gnu awk for windows.

---------- Post updated at 08:01 AM ---------- Previous update was at 07:54 AM ----------

Quote:
Originally Posted by pravin27
You can create bash script like below

script.sh
Code:
#!/bin/sh
awk -F";" 'NR==FNR{a[$1]=$2;next} !a[$1] ||a[$1] < $2 ' source template.txt

Why you want to use this in pipe bcoz we are processing two input flles
I need pipe becouse it must run on many computers, and names of directories and files is uniq for every machine. So first part of pipe takes filename and put it to awk.
Your help improve very much, thank you. It's totally solution. I need now only to cover it for perfect output.
# 14  
Old 11-18-2010
Try this,

test.awk
Code:
BEGIN{FS=";"} NR==FNR{a[$1]=$2;next} !a[$1] ||a[$1] < $2

invocation
Code:
awk -f test.awk source template.txt

This User Gave Thanks to pravin27 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

URGENT Reading a file and assessing the syntax shell script URGENT

I am trying to write a shell script which takes an input file as an arguement in the terminal e.g. bash shellscriptname.sh input.txt. I would like for the file to be read line by line each time checking if the .txt file contains certain words or letters(validating the syntax). If the line being... (1 Reply)
Discussion started by: Gurdza32
1 Replies

3. Shell Programming and Scripting

Compare 2 text file with 1 column in each file and write mismatch data to 3rd file

Hi, I need to compare 2 text files with around 60000 rows and 1 column. I need to compare these and write the mismatch data to 3rd file. File1 - file2 = file3 wc -l file1.txt 58112 wc -l file2.txt 55260 head -5 file1.txt 101214200123 101214700300 101250030067 101214100500... (10 Replies)
Discussion started by: Divya Nochiyil
10 Replies

4. Shell Programming and Scripting

Match list of strings in File A and compare with File B, C and write to a output file in CSV format

Hi Friends, I'm a great fan of this forum... it has helped me tone my skills in shell scripting. I have a challenge here, which I'm sure you guys would help me in achieving... File A has a list of job ids and I need to compare this with the File B (*.log) and File C (extend *.log) and copy... (6 Replies)
Discussion started by: asnandhakumar
6 Replies

5. Shell Programming and Scripting

open 2 files and compare values script - urgent

Hi gurus I have two csv files that are outputs. The file contains data similar to s.no,number1,number2,date1 -------------------------------- 1, a123,482.29,11/28/07 13:00 2,a124,602.7,9/24/07 14:00 3,a125,266.93,10/9/07 16.48 4,a126,785.15,11/14/07 16:08 <file 2> s.no name... (2 Replies)
Discussion started by: inkyponky
2 Replies

6. What is on Your Mind?

Most deadly commands on Unix/Linux !!

lets list the most deadly commands on Unix/Linux and what they do.... > sudo rm -rf / (27 Replies)
Discussion started by: Rahulpict
27 Replies

7. Shell Programming and Scripting

Very urgent :- How to compare string using if statement

Hi How can i compare a string using if statement in a script? For eg: I have filename="abc.sh" if ;then { ....... ....... } fi but this doesnot work .. How will i execute this ?? Thanks in advance (1 Reply)
Discussion started by: jisha
1 Replies

8. Shell Programming and Scripting

[Urgent]how to print the file names into a txt file???

HI, I have a folder with some 120 files...i just want to print all the file filenames(not the content or anything else) onto a file say .txt. please help me with this command Thanks a lot. (15 Replies)
Discussion started by: kumarsaravana_s
15 Replies

9. Shell Programming and Scripting

[urgent need help]compare data

hi all, very need help urgently :( i have a problem compare 2 files from solaris, the 2 files its shown below: data1.log : 6512345678 6512345677 20070131 073824 420 6511111111 6522222222 20070131 103747 87 6522222222 6233333333 ... (2 Replies)
Discussion started by: bucci
2 Replies
Login or Register to Ask a Question