0

I am using c shell and trying to compare 2 files using awk . But the below awk statement doesnt give any result.

Need to acheive this solution in awk using C shell.

awk 'FNR==NR{a[$0]++;next} 
{
{if \!( $0 in a )
{
    print $0
} 
}' cmp1 cmp2 

cmp1 file

file:tst1
md5sum:aED567ZZZ
rowcount:1256

cmp2 file

file:tst1
md5sum:AED567ZZZ
rowcount:1257

o/p expected

rowcount:1257
md5sum:aED567ZZZ
  • 1
    awk 'FNR==NR{a[$0]++;next}!($0 in a)' cmp1 cmp2 – mosvy Apr 26 at 21:38
  • and no, there's no need to escape the ! before ( in csh. – mosvy Apr 26 at 21:39
  • awk 'FNR==NR{a[$0]++}!($0 in a)' cmp1 cmp2 ? – steve Apr 26 at 21:41
  • You need to escape the newlines inside a quoted string in csh.Apart from that dangling brace preceding the if clause. – Rakesh Sharma Apr 27 at 5:30
-1

I cannot take much credit for the solution but here it is

awk 'FNR==NR{a[$0]++;next}
{
{if ( $0 in a == 0 )
{
    print $0
}
}}' cmp1 cmp2

Credit goes to @karthikr and @jeff

PS. Note that you had a missing } in your code sample.

  • Why do we need an additional "}" ? – AbdulWahab Khan Apr 27 at 3:25
  • The if condition should be evaluated only when $0 is not in a (i.e. !( $0 in a )) . In that case will this condition work if ( $0 in a == 0 ) – AbdulWahab Khan Apr 27 at 3:27
-1

Or comm -13 cmp1 cmp2, and you don't have any csh-related entanglements.

  • only if the two files are sorted – Uncle Billy Apr 27 at 12:33
  • If we need to sort the files, cmp1 and cmp2 before passing to the awk command or to the comm command , what should be the working command before passing it. – AbdulWahab Khan Apr 28 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.