bash: Second field separator for a WHILE loop

The name of the pictureThe name of the pictureThe name of the pictureClash 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










share|improve this question









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 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











  • 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















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










share|improve this question









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 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











  • 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













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










share|improve this question









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






share|improve this question









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.











share|improve this question









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.









share|improve this question




share|improve this question








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 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











  • 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











  • 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
















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
















active

oldest

votes











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






Steve Wright is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















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






























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.









 

draft saved


draft discarded


















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.













 


draft saved


draft discarded














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





















































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






Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)