I am trying to read a file line by line and check if the current line contains more than one column. if it contains more than one, I want the script to be interrupted.
I have a file called test and it contains the following ...
ME
TEST
HELLO
WORLD
BOO,HOO
BYE BYE
I found using awk to get the number of columns using the following ...
awk -F',' '{print NF}' test
and it returns ...
1
1
1
1
2
1
Is there a way to make a script output after detecting "2" and print the error message "$ 1" (in this case, BOO, HOO) contains two columns?
source
share