I am currently trying read a csv file with BASH. The 10th [
$f10] value of the csv file must be greater then 0 for a given machine class and machine ID [
m_class] and [
m_id] (these are user defined) . I am
tacing the file as the most recent information is written last. Here is the snippet of code [ignore the echos, as I placed them there too see if my code was entering the while and if loops]:
IFS="," while read f1 f2 f3 f4 f5 f6 f7 f8 f9 f10 f11 f12 f13 f14 f15 do echo "this is while loop" if [ "$f7" == "EnHr" ] && [ "$f10" -gt 0 ] && [ "$f4" == "$m_class" ] && [ "$f5" == "$m_id" ] then hex_sensor_data=$f10 echo "IN IF LOOP: $hex_sensor_data" break fi echo "HEX DATA $hex_sensor_data" done <<<"tac /DIRECTORY/TO/FILE.csv | sed 's/o,632/o,101/g' | sed 's/o,938/o,103/g' | sed 's/o,510/o,112/g' | sed 's/ombo,713/ombo,102/g'"
This while loop renders a 0 value for any m_class m_id, also the
$f10 is in hex value - After
breaking from the
while read loop I want to do some processing with
Q: I want to get the last value which is greater then 0 in the 10th space of the csv file whilst the 7th value of the csv holds EnHr, as well as the 4th and 5th hold for a given
m_id respectively. To do so I need to read the csv file from bottom (latest information) to the top (earliest information) I am doing this with
tac as well as doing some piping. Any help is appreciated!