I have setup like this:
#read a list of files
tr -d \\015 < sample.txt | while IFS=, read -r NAME
do
#grep for lines and do stuff
for VAR in $(grep '.*: {$' $NAME)
do
do some stuff
done
done
Problem is this. It doesn't work, because the for VAR in $(grep '.*: {$' $NAME) adds an unnecessary space and newline to its results.
If I echo $VAR I get the following:
blahblahblah:
{
Now consider this code:
#read a list of files
tr -d \\015 < sample.txt | while IFS=, read -r NAME
do
VAR=$(grep '.*: {$' $NAME)
echo $VAR
done
If I echo $VAR here I get:
blahblahblah: {
Why do I get the extra newline in the first example?