1

I have a file, input.txt, with the following values:

field1|value1
field2|value2
field3|d:\foldername
field4|null

How do I set variables to column1 and column2 so that I can then evaluate column2 for null and display an error message?

I can do this using DOS fairly easily, but I can't figure out how to do it in bash. I researched for a good while and know that IFS is a good option but I don't know how to make it happen in bash.

1 Answers1

0

If you use IFS and read -r you can break the lines up into fields as needed, and then process the fields.

#!/usr/bin/env bash
while IFS='|' read -r column1 column2;  do
    if [ "$column2" == null ] ; then
        echo Found null: "$column1|$column2"
    fi
done < input.txt