I am trying to loop in a file that has multiple rows with multiple columns (fields) with conditions.
Here is an example sample file ( file.txt ):
aaa bbb ccc ddd kkk fff ggg hhh lll ooo sss
... etc...
I want to write a bash script that intersects the first line of the first field, and if the name exists, then the second line continues. If the name of the first line of the first field does not exist, check the second field (in this case, check the name "bbb") and so on until the fourth. I have variable field numbers with a maximum of four (4) fields and a minimum of one field (column) for a given row.
for i in cat file.txt; do echo $i if [ -e $i ]; then echo "name exists" else echo "name does not exist" fi done
Obviously, the above script checks both rows and columns. But I also had to go to the second, third and fourth fields, if the first field does not exist and if the second field does not exist, check the third field before the fourth.
source share