I have a file which contains names with counts for eg:
0622 0031 JOHN MAX 20080622003104. STAT 1.
0622 0031 BILL MAX 20080622003104. STAT 7.
and I have an exception file containing.
BILL
Can anyone help to write a script using this exception files to replace the STAT *(could be any number) to STAT 0 for the names that are in this list
the output should be and the format remains the same
0622 0031 JOHN MAX 20080622003104. STAT 0.
any comments or help appriciated.
I got a script which can do this, but it changes the format.
#!/usr/bin/ksh
nawk '
FNR==NR {ex[$1]; next}
{ $9 = ($1 in ex) ? "0." : $2; print }
' a2 a1 > a3
Since in your first post ti was JOHN and not BILL in the exception file the code works as expected ...
If an entry in the names file matches an entry in the exception file should the stat change only if the current value is 7?
You mentioned the record length and I suppose it's because of the recalculation of the current record; could you post sample of your input data using the code tags.
#! /bin/ksh
cp inp.txt tmp_1.txt
while read line
do
sed "/$line/s/STAT [0-9][0-9]*/STAT 0/g" tmp_1.txt > tmp_2.txt
cp tmp_2.txt tmp_1.txt
done < exp.txt
cat tmp_2.txt
rm tmp_2.txt tmp_1.txt
inp.txt
0622 0031 JOHN MAX 20080622003104. STAT 1
0622 0031 PETER MAX 20080622003104. STAT 3
0622 0031 BILL MAX 20080622003104. STAT 7
0622 0031 MARY MAX 20080622003104. STAT 2