Hi,
I'm trying to get a line returned as is from the below input.csv file in Bash in Linux, and somehow I get an unexpected newline in the middle of my input.
Here's a sample line in input.csv
$> more input.csv
TEST_SYSTEM,DUMMY@GMAIL.COM|JULIA H|BROWN
And here's a very basic while loop to read the contents of input.csv:
INPUT=`cat input.csv`
for read in $INPUT; do
echo "current line: " $read
done
Here is the output:
current line: TEST_SYSTEM,DUMMY@GMAIL.COM|JULIA
current line: H|BROWN
I noticed that when I remove ' H' from the input (if the input.csv line reads
TEST_SYSTEM,DUMMY@GMAIL.COM|JULIA|BROWN),
then the whole line gets printed fine. So there's something fishy with the ' H' format that's driving me nuts.
It's easy to see from your sample input that the issue is the space between the A and the H . You have not written your script in any way that it knows the input file is a CSV file, so your post is a bit confusing.
What did you expect the output to be, exactly, based on the script you posted?
In addition to what RudiC so succinctly analysed: you fell victim to something that is called "field splitting" in the shell. I suggest you look up the concept, it will make the meaning of the suggested IFS variable much clearer.