Что у меня есть:
file.csv
car, speed, gas, color
2cv, 120, 8 , green
vw, 80, , yellow
Jaguar, 250, 15 , red
Benz, , , silver
Что я нашел:
- Следующий скрипт дает мне именно то, что мне нужно, по номеру столбца.
#!/bin/bash
awk -F', *' -v col=3 '
FNR>1 {
if ($col)
maxc=FNR
}
END {
print maxc
}
' file.csv
read -p "For End press Enter or Ctl + C"
Я получаю именно тот результат, который мне нужен (номер последней строки столбца):
* for "col=1" ("car" column), the answer: 5
* for "col=2" ("speed" colomn), the answer: 4
* for "col=3" ("gas" column), the answer: 4
* for "col=4" ("color" column), the answer: 5
То, что я ищу:
- Я ищу способ получить то же самое не с помощью "vol = volumnumber pe vol = 3", а с помощью "vol = columnheadlinevalue pe vol = gas".
Может быть, нужны дополнительные вроде:
col_name=gas # selected column headline
col=get column numer from $col_name # not working part