bash: Second field separator for a WHILE loop

Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
My question is similar to the one asked here:
https://www.unix.com/shell-programming-and-scripting/104336-how-set-ifs-specific-command.html
I'm looking to make a FOR loop into a WHILE loop, but as you see when you read the script
function twokey () wc -w)
echo "$f: There are $keycount keywords."
for keys in $keycount
do
echo "$keys"
echo "Adding keyword $taxt."
exiv2 --keep -M"add Iptc.Application2.Keywords $taxt" -M"add Xmp.dc.subject $taxt" "$f"
((taxt++))
done
exiv2 -g Iptc.Application2.Keywords -Pv "$f"
function dothedeed ()
echo -e "Adding Keywords to e[5;42m$fe[0m."
echo -e "$ft$k"
keycount=$(echo "$k"
function dav ()
echo -e "What text file will I be using?"
read -er item
f=$item
while IFS="^" read -r f k
do
echo -e "File is e[31m$fe[0m"
if [[ ! -f "$f" ]]; then
echo "I don't see $f in this directory."
echo "Moving to next list item."
continue
fi
# dothedeed
twokey
done<"$f"
dav
...it already sets one IFS field separator, a carat, to read the ASCII text file IN. I have tried the script as is, but the "cut" command, on line 21, keeps "landing" it on the first word after the first comma in the string of keywords, which is all it writes to the image file. I'm not sure changing that FOR to a WHILE IFS="," will get me any further along. By my logic it should.
S Wright
bash shell-script read
New contributor
Steve Wright is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
up vote
0
down vote
favorite
My question is similar to the one asked here:
https://www.unix.com/shell-programming-and-scripting/104336-how-set-ifs-specific-command.html
I'm looking to make a FOR loop into a WHILE loop, but as you see when you read the script
function twokey () wc -w)
echo "$f: There are $keycount keywords."
for keys in $keycount
do
echo "$keys"
echo "Adding keyword $taxt."
exiv2 --keep -M"add Iptc.Application2.Keywords $taxt" -M"add Xmp.dc.subject $taxt" "$f"
((taxt++))
done
exiv2 -g Iptc.Application2.Keywords -Pv "$f"
function dothedeed ()
echo -e "Adding Keywords to e[5;42m$fe[0m."
echo -e "$ft$k"
keycount=$(echo "$k"
function dav ()
echo -e "What text file will I be using?"
read -er item
f=$item
while IFS="^" read -r f k
do
echo -e "File is e[31m$fe[0m"
if [[ ! -f "$f" ]]; then
echo "I don't see $f in this directory."
echo "Moving to next list item."
continue
fi
# dothedeed
twokey
done<"$f"
dav
...it already sets one IFS field separator, a carat, to read the ASCII text file IN. I have tried the script as is, but the "cut" command, on line 21, keeps "landing" it on the first word after the first comma in the string of keywords, which is all it writes to the image file. I'm not sure changing that FOR to a WHILE IFS="," will get me any further along. By my logic it should.
S Wright
bash shell-script read
New contributor
Steve Wright is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Welcome to unix.stackexchange.com ! Can you provide an input example, the unwanted output, and what you'd like to get as output, keeping things as short as possible ? To provide the additional info, please edit yr post and place all at the end, after the tag***EDIT:***<BR>. As a side note, the fact thatcut -d, -f2lands you on the first word after the comma (when there is a comma !) is expected, since it is what you are asking it to do. Also it may be useful to add-sto thatcutcmd. If not you might get unexpected results from((taxt++)). More when you provide more info.
– Cbhihe
7 hours ago
It [the script] does NOT "set" anyIFS. The IFS is set by you elsewhere (outside the script) or, if unset, correspond, to bash's default, whic is a simple space. Please consultman bashfor more info on that.
– Cbhihe
7 hours ago
Apart from the above, try this instead of yr while loop:while read -r f k && [ IFS == "^" ]; do .... ; done. Spaces are VERY important.
– Cbhihe
7 hours ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
My question is similar to the one asked here:
https://www.unix.com/shell-programming-and-scripting/104336-how-set-ifs-specific-command.html
I'm looking to make a FOR loop into a WHILE loop, but as you see when you read the script
function twokey () wc -w)
echo "$f: There are $keycount keywords."
for keys in $keycount
do
echo "$keys"
echo "Adding keyword $taxt."
exiv2 --keep -M"add Iptc.Application2.Keywords $taxt" -M"add Xmp.dc.subject $taxt" "$f"
((taxt++))
done
exiv2 -g Iptc.Application2.Keywords -Pv "$f"
function dothedeed ()
echo -e "Adding Keywords to e[5;42m$fe[0m."
echo -e "$ft$k"
keycount=$(echo "$k"
function dav ()
echo -e "What text file will I be using?"
read -er item
f=$item
while IFS="^" read -r f k
do
echo -e "File is e[31m$fe[0m"
if [[ ! -f "$f" ]]; then
echo "I don't see $f in this directory."
echo "Moving to next list item."
continue
fi
# dothedeed
twokey
done<"$f"
dav
...it already sets one IFS field separator, a carat, to read the ASCII text file IN. I have tried the script as is, but the "cut" command, on line 21, keeps "landing" it on the first word after the first comma in the string of keywords, which is all it writes to the image file. I'm not sure changing that FOR to a WHILE IFS="," will get me any further along. By my logic it should.
S Wright
bash shell-script read
New contributor
Steve Wright is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
My question is similar to the one asked here:
https://www.unix.com/shell-programming-and-scripting/104336-how-set-ifs-specific-command.html
I'm looking to make a FOR loop into a WHILE loop, but as you see when you read the script
function twokey () wc -w)
echo "$f: There are $keycount keywords."
for keys in $keycount
do
echo "$keys"
echo "Adding keyword $taxt."
exiv2 --keep -M"add Iptc.Application2.Keywords $taxt" -M"add Xmp.dc.subject $taxt" "$f"
((taxt++))
done
exiv2 -g Iptc.Application2.Keywords -Pv "$f"
function dothedeed ()
echo -e "Adding Keywords to e[5;42m$fe[0m."
echo -e "$ft$k"
keycount=$(echo "$k"
function dav ()
echo -e "What text file will I be using?"
read -er item
f=$item
while IFS="^" read -r f k
do
echo -e "File is e[31m$fe[0m"
if [[ ! -f "$f" ]]; then
echo "I don't see $f in this directory."
echo "Moving to next list item."
continue
fi
# dothedeed
twokey
done<"$f"
dav
...it already sets one IFS field separator, a carat, to read the ASCII text file IN. I have tried the script as is, but the "cut" command, on line 21, keeps "landing" it on the first word after the first comma in the string of keywords, which is all it writes to the image file. I'm not sure changing that FOR to a WHILE IFS="," will get me any further along. By my logic it should.
S Wright
bash shell-script read
bash shell-script read
New contributor
Steve Wright is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Steve Wright is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 2 days ago
New contributor
Steve Wright is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 2 days ago
Steve Wright
11
11
New contributor
Steve Wright is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Steve Wright is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Steve Wright is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Welcome to unix.stackexchange.com ! Can you provide an input example, the unwanted output, and what you'd like to get as output, keeping things as short as possible ? To provide the additional info, please edit yr post and place all at the end, after the tag***EDIT:***<BR>. As a side note, the fact thatcut -d, -f2lands you on the first word after the comma (when there is a comma !) is expected, since it is what you are asking it to do. Also it may be useful to add-sto thatcutcmd. If not you might get unexpected results from((taxt++)). More when you provide more info.
– Cbhihe
7 hours ago
It [the script] does NOT "set" anyIFS. The IFS is set by you elsewhere (outside the script) or, if unset, correspond, to bash's default, whic is a simple space. Please consultman bashfor more info on that.
– Cbhihe
7 hours ago
Apart from the above, try this instead of yr while loop:while read -r f k && [ IFS == "^" ]; do .... ; done. Spaces are VERY important.
– Cbhihe
7 hours ago
add a comment |
Welcome to unix.stackexchange.com ! Can you provide an input example, the unwanted output, and what you'd like to get as output, keeping things as short as possible ? To provide the additional info, please edit yr post and place all at the end, after the tag***EDIT:***<BR>. As a side note, the fact thatcut -d, -f2lands you on the first word after the comma (when there is a comma !) is expected, since it is what you are asking it to do. Also it may be useful to add-sto thatcutcmd. If not you might get unexpected results from((taxt++)). More when you provide more info.
– Cbhihe
7 hours ago
It [the script] does NOT "set" anyIFS. The IFS is set by you elsewhere (outside the script) or, if unset, correspond, to bash's default, whic is a simple space. Please consultman bashfor more info on that.
– Cbhihe
7 hours ago
Apart from the above, try this instead of yr while loop:while read -r f k && [ IFS == "^" ]; do .... ; done. Spaces are VERY important.
– Cbhihe
7 hours ago
Welcome to unix.stackexchange.com ! Can you provide an input example, the unwanted output, and what you'd like to get as output, keeping things as short as possible ? To provide the additional info, please edit yr post and place all at the end, after the tag
***EDIT:***<BR>. As a side note, the fact that cut -d, -f2 lands you on the first word after the comma (when there is a comma !) is expected, since it is what you are asking it to do. Also it may be useful to add -s to that cut cmd. If not you might get unexpected results from ((taxt++)). More when you provide more info.– Cbhihe
7 hours ago
Welcome to unix.stackexchange.com ! Can you provide an input example, the unwanted output, and what you'd like to get as output, keeping things as short as possible ? To provide the additional info, please edit yr post and place all at the end, after the tag
***EDIT:***<BR>. As a side note, the fact that cut -d, -f2 lands you on the first word after the comma (when there is a comma !) is expected, since it is what you are asking it to do. Also it may be useful to add -s to that cut cmd. If not you might get unexpected results from ((taxt++)). More when you provide more info.– Cbhihe
7 hours ago
It [the script] does NOT "set" any
IFS. The IFS is set by you elsewhere (outside the script) or, if unset, correspond, to bash's default, whic is a simple space. Please consult man bash for more info on that.– Cbhihe
7 hours ago
It [the script] does NOT "set" any
IFS. The IFS is set by you elsewhere (outside the script) or, if unset, correspond, to bash's default, whic is a simple space. Please consult man bash for more info on that.– Cbhihe
7 hours ago
Apart from the above, try this instead of yr while loop:
while read -r f k && [ IFS == "^" ]; do .... ; done. Spaces are VERY important.– Cbhihe
7 hours ago
Apart from the above, try this instead of yr while loop:
while read -r f k && [ IFS == "^" ]; do .... ; done. Spaces are VERY important.– Cbhihe
7 hours ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Steve Wright is a new contributor. Be nice, and check out our Code of Conduct.
Steve Wright is a new contributor. Be nice, and check out our Code of Conduct.
Steve Wright is a new contributor. Be nice, and check out our Code of Conduct.
Steve Wright is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f481977%2fbash-second-field-separator-for-a-while-loop%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Welcome to unix.stackexchange.com ! Can you provide an input example, the unwanted output, and what you'd like to get as output, keeping things as short as possible ? To provide the additional info, please edit yr post and place all at the end, after the tag
***EDIT:***<BR>. As a side note, the fact thatcut -d, -f2lands you on the first word after the comma (when there is a comma !) is expected, since it is what you are asking it to do. Also it may be useful to add-sto thatcutcmd. If not you might get unexpected results from((taxt++)). More when you provide more info.– Cbhihe
7 hours ago
It [the script] does NOT "set" any
IFS. The IFS is set by you elsewhere (outside the script) or, if unset, correspond, to bash's default, whic is a simple space. Please consultman bashfor more info on that.– Cbhihe
7 hours ago
Apart from the above, try this instead of yr while loop:
while read -r f k && [ IFS == "^" ]; do .... ; done. Spaces are VERY important.– Cbhihe
7 hours ago