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

I have many files with info about soft, installed on remote machines.
I need to compare this file with template (soft than must be installed) and output file must content info about software that's not installed.

template.txt
software_name1
software_name2
software_name3.1
workstation1_info.txt
software_name3.2
Lantronix
..any other software
software_name1

output must be software_name2, becouse it is not installed, but software_name3.2 is good enough becouse version is more than we need.
So, the task is to show lines that is in template and not in source, using simple regular expressions

I use grep

grep -vxf template source >out

or

grep -Fvf template source >out

But it shows me only lines that is in source and not in template etc...

I need so fast to solve this problem, becouse it is deadly urgent case.
Please help me.

try this,

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

It works with simple lines
How to add here regular expression?
I mean
software_name3.?
software_name2*
etc

Hi,

Why you want to add reg ex. ? you can test given solution with softwar_name3.2 , etc..

Hi.
there's two much different version and packages of software...
So I don't know what the name of it will be in source file.
I know that version of some soft must be >5.x.x.

could you post few lines from original source and template file and desired o/p ?

here's part of template that I tried to use

K-Lite Codec Pack 5.3.4 (Full);5.3.4
McAfee AntiSpyware Enterprise Module;8.7.0.129
MySQL ODBC 3.51 Driver;03.51.05 - Gamma
Windows XP Service Pack 3;20080414.031525
McAfee VirusScan Enterprise;8.7.00003
7-Zip 4.65;4.65.10.0

and here's info from inventory computer

K-Lite Codec Pack 5.3.4 (Full);5.3.4
McAfee AntiSpyware Enterprise Module;8.7.0.129
MySQL ODBC 3.51 Driver;03.51.05 - Gamma
Windows XP Service Pack 3;20080414.031525
McAfee VirusScan Enterprise;8.7.00003
7-Zip 4.58;4.58.10.0

---------- Post updated at 08:31 PM ---------- Previous update was at 08:29 PM ----------

example
Version 7zip archiver must be > 4.58
It could be 4.65, so I need regexp here

---------- Post updated at 08:34 PM ---------- Previous update was at 08:31 PM ----------

In output I need lines from template that do not match any lines from inventory
here it must be
7-Zip 4.65;4.65.10.0

Try...

awk 'BEGIN{FS=";"}NR==FNR{a[$1]=$2;next}a[$1]<$2||!a[$1]' template source

that does not work properly

I show you what I have and what I need

template

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

source

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

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

 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

I hope this will solve your problem

awk -F";" 'NR==FNR{a[$1]=$2;next} !a[$1] ||a[$1] < $2 ' source template.txt
1 Like

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.

You can create bash script like below

script.sh

#!/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

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

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.

Try this,

test.awk

BEGIN{FS=";"} NR==FNR{a[$1]=$2;next} !a[$1] ||a[$1] < $2

invocation

awk -f test.awk source template.txt
1 Like

I think it's time to learn some awk, I tried and i liked it.