in reply to A Christmas detour: it's the simplest damn things that bite us sometimes
Let me teach you another lesson here, equally important. If the output is weird, check the input.
You mention cygwin, which adds some hints. The input contains MSWin32 EOL characters, so xxd shows it as
00000000: 4350 414e 3a3a 4d65 7461 0d0a 4578 7455 CPAN::Meta..ExtU 00000010: 7469 6c73 3a3a 4275 696c 6465 720d 0a45 tils::Builder..E 00000020: 7874 5574 696c 733a 3a42 7569 6c64 6572 xtUtils::Builder 00000030: 3a3a 436f 6d70 696c 6572 0d0a 4578 7455 ::Compiler..ExtU 00000040: 7469 6c73 3a3a 436f 6e66 6967 0d0a 4578 tils::Config..Ex 00000050: 7455 7469 6c73 3a3a 4865 6c70 6572 730d tUtils::Helpers. 00000060: 0a45 7874 5574 696c 733a 3a49 6e73 7461 .ExtUtils::Insta 00000070: 6c6c 5061 7468 730d 0a47 6574 6f70 743a llPaths..Getopt: 00000080: 3a4c 6f6e 670d 0a4c 6973 743a 3a55 7469 :Long..List::Uti 00000090: 6c0d 0a54 4150 3a3a 4861 726e 6573 730d l..TAP::Harness. 000000a0: 0a .
Do you see those 0d bytes? Strawberry Perl (or any other perl compiled on MSWin) would recognise them, but cygwin Perl is of the *nix kind, so it expects 0a only.
The output you got was not exactly what you thought. The newlines were correctly replaced by spaces, but the carriage returns remained in the data, causing the cursor to return left and overwrite the text again and again.
tr '\n' ' ' < input| xxd 00000000: 4350 414e 3a3a 4d65 7461 0d20 4578 7455 CPAN::Meta. ExtU 00000010: 7469 6c73 3a3a 4275 696c 6465 720d 2045 tils::Builder. E ...
You see? We have 20 (the space) there, but it's preceded by 0d.
What would I use? Any of the following:
perl -pe 'tr/\n\r/ /d' perl -pe 's/\s+/ /' tr -s '\n\r' ' '
|
|---|