I am loading a file into variables, the problem is that the file is formatted in Windows, I believe, so I get a ^M instead of a newline.
How do I modify it when the value is in the variable? I am aware that I can modify the source in VI (I use OS X, by the way), but I can't modify the original file, only read it, so I have to remove the ^M from the variable.
From my understanding, \n is not the same as ^M, so tr command won't work.
EDIT
It seems the question is not clear; so this is the clarification.
I do parse the file line by line; each line has a 2 values, separated by tab and at the end of each line, there is a ^M, it does look like this:
value1 value2^M value3 value4^M value5 value6^M value7 value8^M My workflow is pretty straightforward and simple: the txt file contain what you see above, the loop separate fields and for each line get the values; when I print the second value it has the ^M, which I would like to remove
while IFS=$'\t' read -r -a line do Type1="${line[0]}" Type2="${line[1]}" done < $TXTFILE Which means taht when I print Type1 it is fine, but Type2 variable contain the ^M. I did use tr and it didn't work, I did use sed to remove the last character of the variable, and it didn't work. Hope this clarify my question. Thanks
sed 's|\r||' fileinstead offiletrbut the question is way to broad. We don't know what the input or output are, nor what the script looks like.