Hello

I am trying to compare 2 files using awk. They have the same seperators, same columns, same rows.

I need to go through both and see at which line they differ, adn then save those differences to another file.

I have tried many methods but none seem to work.

I'm not very familiar with the syntax of AWK, as I am just starting off with it.

Here is my file1:

User Parameter,Entity Name,Cell ID,Type SubCell / TX / FHSY / DRI / TDMA,Instance CHGR / TX / FHSY / DRI / TDMA,CellR ID,Vendor Parameter,Planned Value,Translated Value,Network Value,Override Level,Override Node,,,,Vendor,Technology,Version
User Parameter,Entity Name,Cell ID,Type SubCell / TX / FHSY / DRI / TDMA,Instance CHGR / TX / FHSY / DRI / TDMA,CellR ID,Vendor Parameter,Planned Value,Translated Value,Network Value,Override Level,Override Node,,,,Vendor,Technology,Version
,,,,,,,,,,,,,,
,,,,,,,,,,,,,,
Access Grant Blocks Reserved,CELL,1A,,,,AGBLK,5,5,1,CELL,1A,,,,ERICSSON,GSM,07B
Access Grant Blocks Reserved,CELL,1A,,,,AGBLK,5,5,1,CELL,1A,,,,ERICSSON,GSM,07B
Access Grant Blocks Reserved,CELL,1B,,,,AGBLK,2,2,1,CELL,1B,,,,ERICSSON,GSM,07B
Access Grant Blocks Reserved,CELL,1B,,,,AGBLK,2,2,1,CELL,1B,,,,ERICSSON,GSM,07B
Access Grant Blocks Reserved,CELL,1C,,,,AGBLK,3,3,1,CELL,1C,,,,ERICSSON,GSM,07B
Access Grant Blocks Reserved,CELL,1C,,,,AGBLK,3,3,1,CELL,1C,,,,ERICSSON,GSM,07B
Access Grant Blocks Reserved,CELL,2A,,,,AGBLK,7,7,1,CELL,2A,,,,ERICSSON,GSM,08B
Access Grant Blocks Reserved,CELL,2A,,,,AGBLK,7,7,1,CELL,2A,,,,ERICSSON,GSM,08B
Access Grant Blocks Reserved,CELL,2B,,,,AGBLK,4,4,1,CELL,2B,,,,ERICSSON,GSM,08B
Access Grant Blocks Reserved,CELL,2B,,,,AGBLK,4,4,1,CELL,2B,,,,ERICSSON,GSM,08B
Access Grant Blocks Reserved,CELL,2C,,,,AGBLK,0,0,1,CELL,2C,,,,ERICSSON,GSM,08B
Access Grant Blocks Reserved,CELL,2C,,,,AGBLK,0,0,1,CELL,2C,,,,ERICSSON,GSM,08B
Access Grant Blocks Reserved,CELL,3A,,,,AGBLK,1,1,1,CELL,3A,,,,ERICSSON,GSM,08B
Access Grant Blocks Reserved,CELL,3A,,,,AGBLK,1,1,1,CELL,3A,,,,ERICSSON,GSM,08B
Access Grant Blocks Reserved,CELL,3B,,,,AGBLK,6,6,1,CELL,3B,,,,ERICSSON,GSM,08B
Access Grant Blocks Reserved,CELL,3B,,,,AGBLK,6,6,1,CELL,3B,,,,ERICSSON,GSM,08B
Access Grant Blocks Reserved,CELL,3C,,,,AGBLK,4,4,1,CELL,3C,,,,ERICSSON,GSM,08B
Access Grant Blocks Reserved,CELL,3C,,,,AGBLK,4,4,1,CELL,3C,,,,ERICSSON,GSM,08B

Here is my file 2:

User Parameter,Entity Name,Cell ID,Type SubCell / TX / FHSY / DRI / TDMA,Instance CHGR / TX / FHSY / DRI / TDMA,CellR ID,Vendor Parameter,Planned Value,Translated Value,Network Value,Override Level,Override Node,,,,Vendor,Technology,Version
User Parameter,Entity Name,Cell ID,Type SubCell / TX / FHSY / DRI / TDMA,Instance CHGR / TX / FHSY / DRI / TDMA,CellR ID,Vendor Parameter,Planned Value,Translated Value,Network Value,Override Level,Override Node,,,,Vendor,Technology,Version
,,,,,,,,,,,,,,
,,,,,,,,,,,,,,
Access Grant Blocks Reserved,CELL,1A,,,,AGBLK,0,0,1,CELL,1A,,,,ERICSSON,GSM,07B
Access Grant Blocks Reserved,CELL,1A,,,,AGBLK,0,0,1,CELL,1A,,,,ERICSSON,GSM,07B
Access Grant Blocks Reserved,CELL,1B,,,,AGBLK,2,2,1,CELL,1B,,,,ERICSSON,GSM,07B
Access Grant Blocks Reserved,CELL,1B,,,,AGBLK,2,2,1,CELL,1B,,,,ERICSSON,GSM,07B
Access Grant Blocks Reserved,CELL,1C,,,,AGBLK,3,3,1,CELL,1C,,,,ERICSSON,GSM,07B
Access Grant Blocks Reserved,CELL,1C,,,,AGBLK,3,3,1,CELL,1C,,,,ERICSSON,GSM,07B
Access Grant Blocks Reserved,CELL,2A,,,,AGBLK,7,7,1,CELL,2A,,,,ERICSSON,GSM,08B
Access Grant Blocks Reserved,CELL,2A,,,,AGBLK,7,7,1,CELL,2A,,,,ERICSSON,GSM,08B
Access Grant Blocks Reserved,CELL,2B,,,,AGBLK,4,4,1,CELL,2B,,,,ERICSSON,GSM,08B
Access Grant Blocks Reserved,CELL,2B,,,,AGBLK,4,4,1,CELL,2B,,,,ERICSSON,GSM,08B
Access Grant Blocks Reserved,CELL,2C,,,,AGBLK,0,0,1,CELL,2C,,,,ERICSSON,GSM,08B
Access Grant Blocks Reserved,CELL,2C,,,,AGBLK,0,0,1,CELL,2C,,,,ERICSSON,GSM,08B
Access Grant Blocks Reserved,CELL,3A,,,,AGBLK,1,1,1,CELL,3A,,,,ERICSSON,GSM,08B
Access Grant Blocks Reserved,CELL,3A,,,,AGBLK,1,1,1,CELL,3A,,,,ERICSSON,GSM,08B
Access Grant Blocks Reserved,CELL,3B,,,,AGBLK,6,6,1,CELL,3B,,,,ERICSSON,GSM,08B
Access Grant Blocks Reserved,CELL,3B,,,,AGBLK,6,6,1,CELL,3B,,,,ERICSSON,GSM,08B
Access Grant Blocks Reserved,CELL,3C,,,,AGBLK,4,4,1,CELL,3C,,,,ERICSSON,GSM,08B
Access Grant Blocks Reserved,CELL,3C,,,,AGBLK,4,4,1,CELL,3C,,,,ERICSSON,GSM,08B

The resultant file should contain:

Access Grant Blocks Reserved,CELL,1A,,,,AGBLK,5,5,1,CELL,1A,,,,ERICSSON,GSM,07B
Access Grant Blocks Reserved,CELL,1A,,,,AGBLK,0,0,1,CELL,1A,,,,ERICSSON,GSM,07B

Since that is where it differs

My script is:

#!/bin/bash
awk -F',' -v file1="$1" -v file2="$2" '{print;}1' OFS="," diff $1 $2 > resultfile.csv

I want to call this script from the command line and parse the two files to it from the command line.

Can you help me?

How about starting with

diff $1 $2 > resultfile.csv

commented: Easy, breezy, beautiful... another fine delivery by the main'ers doomer! +8

This works for me:

awk -F',' -v file1="$1" -v file2="$2" 'NR == FNR {A[$0] = 1; next} !A[$0]' OFS="," $1 $2 > resultfile.csv
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.