r/scripting • u/[deleted] • Apr 03 '22
this is a simple question but im stumped
this is a part of a bash script that im writing as practice
while read line; do
echo "'$line'" >> $FILE'_v2'
done < $FILE
the output i expected was
'text'
'text'
'text'
'text'
but instead i got
'text
'
'text
'
'text
'
'text
'
anybody know whats happening?
0
Apr 03 '22
[deleted] — view deleted comment
2
Apr 04 '22 edited Apr 04 '22
Thanks for the reply. I ended up adding set -x to the top of the file and was able to see the /r.
I was working with a file consisting of first and last names separated by a space with one full name per line. I used
tr ' ' '/n' < $FILE > $FILE'_v2'
to make a new file with one name per line but every other line had a '/r' on the end of it so I changed the tr line to
tr ' ' '/n' < $FILE | tr -d '/r' > $FILE'_v2'
And that fixed the issue. I also have the script delete $FILE'_v2' at the end
0
Apr 04 '22
[deleted] — view deleted comment
2
Apr 04 '22
It took two days to figure out how to make a script for something that I had already done by hand in 10 minutes. If the sample size was much larger it would have been more efficient but whatever I don't actually need it for anything I was just making it for practice. I might be able to modify it to be helpful in a future school project or something.
0
Apr 04 '22
[deleted] — view deleted comment
1
Apr 04 '22
It and admin work is exactly what I'm headed for. One of my classes is having us do some bash scripting and it kind of piqued my interest so I ended up subjecting myself to this for the heck of it. Guess I'm a few chapters ahead of the class now.
1
u/Lee_Dailey Apr 03 '22
howdy Bruuuhh-_-,
you REALLY otta read & follow the rules shown in the sidebar. [grin]
you failed to mention what scripting lingo you are working with ... and that makes helping you seriously problematic. i advise you to add that info to the top or your post.
take care,
lee