mercredi 8 novembre 2017

If statement in bash to check if column matches string.

I'm relatively new to scripting in general, and I'm running into a bit of a problem. I have this snippet of code that is used in one of our csv manipulation scripts. See below.

if [[ '$349' = ’Negative’ ]] || [[ '$349' = ’Positive’ ]] || [[ '$349' = ’Pending’ ]]
                then
                echo "neg/pos"
                cut -d, -f 5,6,247,348,352 "$f" > "${f}.tmp"
                else
                echo "apc/etc"
                cut -d, -f 5,6,247,349,353 "$f" > "${f}.tmp"
        fi
        mv ${f}.tmp /home/Outgoing/$f
        rm -f $f

Basically have a large csv file that is generated in our app, and I want to check the contents of column 349. If it contains either "Negative", "Positive", or "Pending" it will cut the file down to the five columns in the then statement.

If not, it will cut them to the 5 columns in the else statement.

I have a test file running through it. Column 349 clearly has "Negative" inside the file, but it keeps through it to the else statement.

Can someone help? I feel like I'm missing something very simple.

Thank you!

Aucun commentaire:

Enregistrer un commentaire