I want to print part of the content of a .csv file in another file if there is a match with some condition:
The csv content is like this
abc test;ABCtest.it
xyz test;XYZtest.com
I read the content in a variable and I grep it for some string
csvContent=$(<$file.csv)
csvRow="$(echo "$csvContent" | grep -i "abc test")"
IFS=';' read -a array <<< "$csvRow"
name="${array[0]}"
url="${array[1]}"
echo -ne "\n$url,$name" >> "$outputDir/$fileName"
But the output file doesn't contain the url part
If I try this
echo $url
it's printed on the terminal!
I've tried also with printf and with an hardcoded filename but nothing!
printf '%s %s\n' "$url" "$name" >> test.txt
It seems that when I try to concatenate another thing (a variable or a string) after the variable $url some part of this is deleted or overwritten into the output file
For example if I try with this
printf '%s %s\n' "$url" "pp" >> test.txt
What I get with a simple cat test.txt is this :
pptest.it
it is as if part of it was overwritten with a starting empty space
the content of the variable $url must be ABCTest.it
it's very strange
ABCtest.it\r
and when you useecho -e
that carriage return will send the cursor back to the start of the line, and the comma and the name will overwrite the url.csvRow=$(grep -i "abc test" "$file.csv")
.