Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk code error for removing duplicate records between 2 files 1

Status
Not open for further replies.

Coop197823

Programmer
Sep 3, 2015
2
US
I found this bit of awk code that compares the first column of two files and then deletes the duplicate records of the second file.

Code:
 awk 'FNR==NR{a[$1];next};!($1 in a)' file1 file2 > file3
When I run the code, I get an error that says: ^ invalid char ''' in expression

I am very new to awk coding, so I do not too sure what is causing the error. Any help would be greatly appreciated! Thanks in advance!
 
Hi

Based on the error message I suppose you are running it on Windows. In that case you could
[ul]
[li]Run it in Cygwin's terminal. There you will benefit of all the Linux shell features, including the possibility to use single quotes ( ' ) as string delimiters.[/li]
[li]Replace single quote ( ' ) with double quotes ( " ). Not sure, but maybe for this extremely simple code will work.[/li]
[li]Put all code in a file and pass that to the interpreter :
Code:
[navy]FNR[/navy][teal]==[/teal]NR[teal]{[/teal]a[teal][[/teal][navy]$1[/navy][teal]];[/teal][b]next[/b][teal]};!([/teal][navy]$1[/navy] [b]in[/b] a[teal])[/teal]
Code:
awk -f nodup.awk file1 file2 > file3
[/li]
[/ul]

If not, then you will have to give us more details about system, shell and Awk implementation and version.

Feherke.
feherke.ga
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top