How can I replace multiple empty lines with a single empty line in bash?

后端 未结 14 2373
难免孤独
难免孤独 2020-12-13 06:14

I have a file that contains:

something



something else

something else again

I need a bash command, sed/grep w.e that will produce the fo

14条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-13 06:34

    Use python:

    s = file("filename.txt").read()
    while "\n\n\n" in s: s = s.replace("\n\n\n", "\n\n")
    import sys
    sys.stdout.write(s)
    

提交回复
热议问题