Let\'s say we have a text file with 1000 lines.
How can we delete new line characters from line 20 to 500 (replace them with space for example)?
My try:
Using a perl one-liner to strip the newline:
perl -i -pe 'chomp if 20..500' file
Or to replace it with a space:
perl -i -pe 's/\R/ / if 20..500' file
Switches:
-i: Edit <> files in place (makes backup if extension supplied)-p: Creates a while(<>){...; print} loop for each “line” in your input file. -e: Tells perl to execute the code on command line. Code:
chomp: Remove new line20 .. 500: if Range operator .. is between line numbers 20 to 500