Delete \n characters from line range in text file

后端 未结 4 1240
春和景丽
春和景丽 2021-01-29 05:07

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:

4条回答
  •  渐次进展
    2021-01-29 05:48

    This might work for you (GNU sed):

    sed -r '20,500{N;s/^(.*)(\n)/\2\1 /;D}' file
    

    or perhaps more readably:

    sed ':a;20,500{N;s/\n/ /;ta}' file
    

提交回复
热议问题