I copied and pasted the code off the site just to make sure there wasn't an issue in me typing in the code. There wasn't. I suspect the issue is somewhere on your end - almost certainly in the format of the alex_data file. Here are all the files I used etc and an example of the run.
This was the first data file
> cat alex_data.txt
Code:
Bank ID|Acct_number
ID123|2245,3456,002245,1234
ID123|77778900000000
ID123|112244
ID123|4455,6666,0004455
This was the 2nd data file
> cat CFJANDATA.txt
Code:
Bank ID|Acct_number
ID123|2245
ID123|777789
ID123|112244
ID123|6666
ID123|888889
ID123|667788
This was the script
> cat tmp.sh
Code:
#!/bin/sh
cat alex_data.txt | \
sed 's/^.*|/,/' | \
sed 's/$/,/' | \
sed 's/,00*/,/' \
> tmp.dat
for LINE in `cat CFJANDATA.txt`
do
ACC=`echo $LINE | sed 's/^.*|0*//' | sed 's/ *$//'`
ACC=",$ACC,"
CNT=`grep -c $ACC tmp.dat`
if test $CNT -eq 0
then
echo $LINE not found
fi
done
exit
and this is what it produces
> ./tmp.sh
Code:
Bank not found
ID123|777789 not found
ID123|888889 not found
ID123|667788 not found
I guess your data isn't in the format you specified but to debug it is simple. Run the cat through the first sed command and view the output. Then run the cat through the first 2 sed commands and view the output. When it suddenly goes blank - you've found the issue! I assume you're familiar with the sed command.
Code:
cat alex_data.txt | sed 's/^.*|/,/'
then
Code:
cat alex_data.txt | sed 's/^.*|/,/' | sed 's/$/,/'
etc
Mike