How to compare two files in shell script?

ALN picture ALN · Oct 9, 2009 · Viewed 11.4k times · Source

Here is my scenario. I have two files which are having records with each record's 3-25 characters is an identifier. Based on this I need to compare both of them and update the old file with the new file data if their identifiers match. Identifiers start with 01. Please look at the script below. This is giving some error as "argument expected at line 12 which I am not able to understand.

#!/bin/ksh
while read line
  do
    c=`echo $line|grep '^01' `
    if [ $c -ne NULL ];
      then
        var=`echo $line|cut -c 3-25`
    fi
    while read i
      do
        d=`echo $i|grep '^01' `
        if [ $d -ne NULL ];
          then
            var1=`echo $i|cut -c 3-25`
            if [ $var -eq $var1 ];
              then
                $line=$i
            fi
        fi
      done < test_monday
  done < test_sunday

Please help me out thanks in advance

Answer

NawaMan picture NawaMan · Oct 9, 2009

I think what you need is :

if [ "$d" != NULL ];

Try.