linux bash build command with strings from csv

336 views Asked by At

I am pretty new to bash (and linux overall).

Been researching the whole day thinking this was a simple fix that I was not understanding but I've tried a thousand different things and still cannot make it work... need an extra pair of eyes and some advice please.

I have a csv with only one column that hosts names of properties hosted in PasswordVault that I need to query for their password using the PasswordVault client.

This is a working query command:

/opt/CARKaim/sdk/clipasswordsdk GetPassword -p AppDescs.AppID=TEST-APP -p Query="safe=TEST-SAFE;folder=root;object=TEST-SAFE.dev-pwd" -p RequiredProps=Address,UserName -o Password,PassProps.UserName

I am testing with only 2 values in the CSV:

TEST-SAFE.dev-pwd
TEST-SAFE.prd-pwd

When I do the following:

while IFS="," read f1
do
    echo $f1
    /opt/CARKaim/sdk/clipasswordsdk GetPassword -p AppDescs.AppID=TEST-APP -p Query="safe=TEST-SAFE;folder=root;object=**$f1**" -p RequiredProps=Address,UserName -o Password,PassProps.UserName
done < extractiontest.csv

I get the following output:

TEST-SAFE.dev-pwd -p RequiredProps=Address,UserName -o Password,PassProps.UserNameT-APP -p Query=safe=TEST-SAFE;folder=root;object=TEST-SAFE.dev-pwd TEST-SAFE.prd-pwd -p RequiredProps=Address,UserName -o Password,PassProps.UserNameT-APP -p Query=safe=TEST-SAFE;folder=root;object=TEST-SAFE.prd-pwd

Seems as if the portion of the string that comes after the variable, is overwriting the portion of the string that's before the variable and up to it.

I've tried separating the string in multiple variables and try concatenating them one after the other.

I've tried substituting the string with XXX and then doing:

stri="${originalstring//XXX/${f1}}"
echo $stri

I've tried eval.

I've tried different combinations of single vs. double quotes

I even tried having the command as a line in the csv file.

Cannot make it work... :(

HELP? :)

I would really appreciate it!

1

There are 1 answers

1
czvtools On BEST ANSWER

Seems that your CSV file contains '\r' character at the end of the line. More precisely the line ends with '\r\n' just as it would under DOS/Windows. In Bash the end on the line should contain only a single '\n' character. Once you remove the "\r" from the file it would work nicely. For a large file you might use "dos2unix < input.csv > correct.csv" and user the output.csv for your script.