I’m using perl from command line to to replace duplicate spaces from a text file.
The command I use is:
perl -pi -e 's/\s+/ /g' file.csv
The problem: This procedure removes also the new lines in the resulting file….
Any idea why this occur?
Thanks!
\smeans the five characters:[ \f\n\r\t]. So, you’re replacing newlines by single spaces.In your case, the simplest way is to enable automatic line-ending processing with
-lflag:This way, newlines will be chomped before
-estatement and appended after.