0

I'm writing a script and here's how i'm inputting into the CurrentOutput.csv file.

echo "$col1,$col2" >> CurrentOutput.csv 

Input.txt

1.2.3.4
2.3.4.5
3.4.5.6

CurrentOutput.csv

1.2.3.4
,DNS1
2.3.4.5
,DNS2
3.4.5.6
,DNS3

DesiredOutput.csv

1.2.3.4,DNS1
2.3.4.5,DNS2
3.4.5.6,DNS3

I've tried echo -e "$col1,$col2\c" and echo -n "$col1,$col2". Is it because I'm writing from a .txt file to a .csv file? What am I missing here?

2
  • How are you getting col1 and col2?
    – muru
    Dec 10, 2014 at 15:47
  • a .csv file is a Text file but with a comma separated values, so it doesn't matter the what extension it is, what i see is that there is an EOL character in the end of the input value of 1.2.3.4 like if there is this in a C code 1.2.3.4\0 now what i think you should do is to remove that EOL character, try this col1=$(echo $col1 | tr -d '\n') before calling the echo "$col1,$col2"
    – younes
    Dec 10, 2014 at 15:53

1 Answer 1

0

Never mind I found out the answer, there was carriage returns and an ^M char which I had never seen. This question can be deleted.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .