and val_id.txt
235649;05;2563;598
235649;05;2563;598
564564;05;2563;598
235649;05;2563;598
235649;05;2563;598
212564;05;2563;598
(thesse are small samples of the actual files)
What I need to do is to use awk to get the first column of val_id.txt and then search gmrd.txt for any records with instances of the value occuring in the first column of vali_id.txt - if it finds any then it needs to replace the second column of that record by 05
Any help appreciated
I get the following error message:
./split.sh[2]: 235649;05;2563;598: syntax error
with the following code:
for i in $(< val_id.txt );do
index[i]="$i"
export index
When you do "for i in $(< val_id.txt );do", i will be set to one line of input after another. For example, "235649;05;2563;598". This is not a valid subscript, yet the next line, "index[i]=$i" tries to use i as an index. Even if that had worked, you cannot usefully export an array. You should probably rewrite this to use just ksh or just awk. It's not very clear what you really want to do, so I can't really suggest specific code.
What I am trying to do is to get look in the file val_id.txt and take those values in there - if I find instances of those values occuring in gmrd.txt then I want to replace the second column of values with something else say '05'
#! /usr/bin/ksh
exec < val_id.txt
i=0
while IFS=";" read f1 f2 f3 f4 ; do
index="$f1"
((i=i+1))
done
i=0
while ((i<${#index})) ; do
echo ${index}
((i=i+1))
done
exec < gmrd.txt
while IFS=";" read f1 f2 f3 f4 ; do
found=0
i=0
while ((i<${#index})) ; do
[[ $f1 = ${index} ]] && found=1
((i=i+1))
done
if ((found)) ; then
f2="xyz"
fi
echo "${f1};${f2};${f3};${f4}"
done
exit 0
awk '
BEGIN {
FS = OFS = ";"
while (getline < "val_id.txt" > 0)
arr[$1] = 1
}
$1 in arr {
$2 = 50
$NF = $NF "<---debug: line changed"
}
{print}
' gmrd.txt
Tested...
235649;50;2563;598<---debug: line changed
291802;00;2563;598
314634;00;235649;598
235649;50;2563;598<---debug: line changed
393692;00;2563;598
411805;00;2563;598
411805;00;2563;598
235649;50;2563;598<---debug: line changed
414037;00;2563;598
etc.