on a POSIX shell, no Python and no awk available (so don't bother telling me I should use a "real" programming language) I have to loop through a csv file.
https://datacadamia.com/lang/bash/read
My initial guess was :
while IFS=";" read -r rec_name rec_version rec_license rec_origin rec_modification rec_newlicense
do
if [ "$name" = "$rec_name" ]; then
# if [ "$version" = "$rec_version" ]; then
if [ "$license" = "$rec_license" ]; then
license="$rec_newlicense"
fi
# fi
fi
done < <(tail -n +2 "${output_file%%.*}.csv")
But the last line wasn't "posix" compliant. So I tried :
while IFS=";" read -r rec_name rec_version rec_license rec_origin rec_modification rec_newlicense
do
if [ "$name" = "$rec_name" ]; then
# if [ "$version" = "$rec_version" ]; then
if [ "$license" = "$rec_license" ]; then
license="$rec_newlicense"
fi
# fi
fi
done < "${output_file%%.*}.csv"
That did the trick, somehow, but the header line was processed as well.
Another problem was that the fields 'rec_version', 'rec_origin' and 'rec_modification' weren't referenced.
How to ignore them ?
Because I also tried :
while IFS=";" read -r -a rec
do
if [ "$name" = "${rec[0]}" ]; then
# if [ "$version" = "${rec[1]}" ]; then
if [ "$license" = "${rec[2]}" ]; then
license="${rec[5]}"
fi
# fi
fi
done < "${output_file%%.*}.csv"
But then I get :
read: line 93: illegal option -a
So, your take on this ?
Regards.
awk
? Awk is POSIX so it's really strange. Is this an embedded system? Does it also not have other basic tools likecut
orperl
orsed
? – terdon Feb 16 '22 at 09:47perl
? – terdon Feb 16 '22 at 10:26