python - Sed -i is creating new lines and printing output -
we have script compares 2 csv files rows , printing “match found” or “not found” output @ end of 2nd file each row. working good, have updated cygwin, not sure went wrong, prints output next line rows. has changed new version of cygwin- python, , shell
below code line using:
sed -i "${linenum}s/$/,found/" file2.csv file1.csv abcd efgh ijkl mnop qrst xyz file2.csv abcd efgh ijkl found mnop qrst xyzzz not found
it should print above. displaying below.
file2.csv abcd efgh ijkl found mnop qrst xyzzz not found
your appreciated.
this looks issue newlines. windows platforms use \r\n
newline sequence, whereas unix platforms use \n
alone. if file contains \r\n
, code inserting content after \r
, before \n
, that's implicated.
an easy fix convert files unix format first, , (optionally) when you're done:
dos2unix file2.csv sed -i "${linenum}s/$/,found/" file2.csv unix2dos file2.csv ## if want dos-style newlines
Comments
Post a Comment