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
I think what you need is :
Try.
Unless you are writing a script for portability to the original Bourne shell or others that do not support the feature, in Bash and ksh you should use the
[[
form of test for strings and files.There is a reduced need for quoting and escaping, additional conditions such as pattern and regular expression matching and the ability to use
&&
and||
instead of-a
and-o
.Also, "NULL" is not a special value in Bash and ksh and so your test will always succeed since
$d
is tested against the literal string "NULL".or
For numeric values (not including leading zeros unless you're using octal), you can use numeric expressions. You can omit the dollar sign for variables in this context.
It's not necessary to use
echo
andcut
for substrings. In Bash and ksh you can do:Note:
cut
uses character positions for the beginning and end of a range, while this shell construct uses starting position and character count so you have to adjust the numbers accordingly.And it's a good idea to get away from using backticks. Use
$()
instead. This can be nested and quoting and escaping is reduced or easier.I think you could use the DIFF command