Reputation: 44
I have usernames and passwords stored in .txt file with double dot and i would like to read from it and store the first half in variable and second half in variable.
Example : kmyghz1:aa12345bb12345cckmyghz1
cat ./examples/secrets.txt | while IFS=':' | read variable1 variable2 do \
echo $variable1 \
echo $variable2 \
done
Can anyone help?
Upvotes: 0
Views: 1120
Reputation: 44
Thank you for your input and this is the right answer that worked for me!
while IFS=: read -r userName password
do
echo "$userName"
echo "$password"
done < ./instabut/examples/secret.txt
Upvotes: 0
Reputation: 532063
IFS=:
by itself is not a command; it's a pre-command assignment for the read
command. Drop the pipe symbol (|
) separating them. You are also missing either a semicolon or a newline character preceding the do
keyword.
while IFS=: read variable1 variable2; do
echo "$variable1"
echo "$variable2"
done < ./examples/secrets.txt
The backslashes are unnecessary, and parameter expansions should always be quoted.
Upvotes: 1