I have this file called viagens.txt:
2018-10-01:88020:88013:6:4.2
2018-10-01:88020:88014:8:3.8
I want to create a script that, in each line, checks the second column (in this case, in both cases it would return "88020").
However, right now, I can't filter it to get that number on the 2nd column. I have this code:
#!/bin/bash
fich=viagens.txt
condutores=condutores.txt
if [ -f $fich ];then
for f in $(cat $fich); do
condutor=$(cut -f2 $f)
echo $condutor
done
else
echo "Ficheiro nao existe"
fi
I also tried
#!/bin/bash
fich=viagens.txt
condutores=condutores.txt
if [ -f $fich ];then
for f in $(cat $fich); do
condutor=$(cat $f | cut -d' ' -f2)
echo $condutor
done
else
echo "Ficheiro nao existe"
fi
What am I doing wrong?
Thanks in advance.