Search code examples
perlnewlinecarriage-returnlinefeed

Removing line feeds or carriage returns from excel with perl


whenever I try a read a row in a .csv file it stops treating the row as a single row and stores it in multiple arrays, as supposed to just one. What i'm seeing is as I read a .csv file it seems to containg some carriage returns/ these weird squares when i open it in notepad. I want to remove these characters from the file so that i can properly read the .csv without it exiting too early. How would I go about doing this with a perl script.


Solution

  • You can clean up trailing whitespace with the chomp() function in perl. You can use something like this to chomp all trailing whitespace and replace it with a single newline:

    perl -ne 'while(chomp) { } print "$_\n";' filename.csv