Change three or more empty lines into two using bash, sed or awk

PowerCwel

Lets say that we have string containing words and multiple empty lines. For instance

"1\n2\n\n3\n\n\n4\n\n\n\n2\n\n3\n\n\n1\n"

I would like to "shrink" three or more empty lines into two using bash, sed or awk to obtain string

"1\n2\n\n3\n\n4\n\n2\n\n3\n\n1\n"

Has anybody an idea?

karakfa

with awk

$ awk -v RS= -v ORS='\n\n' 1 file

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Why can't I sed two [or more..] empty lines to one empty line?

分類Dev

Using sed / awk to change words between two patterns

分類Dev

Change header using sed or awk

分類Dev

deleting lines between rows in a text file using awk or sed

分類Dev

Squeeze multiple empty lines with sed

分類Dev

How to replace one line with two lines using sed in csh on BSD?

分類Dev

Delete 'N' no lines only on the Nth occurrence of a pattern in a file using the sed/awk command

分類Dev

Get values from beginning of file, Insert values as new columns, trim beginning lines using AWK/GAWK/SED

分類Dev

How to remove series of lines in a file on hp unix using awk or sed or grep

分類Dev

Text Manipulation using sed or AWK

分類Dev

String Replacing using Sed or Awk

分類Dev

Bash - Sed / Awk replacing string with new line

分類Dev

sed/awk remove newline on two pattern matches

分類Dev

Extract two variables and rewrite multiple lines with sed

分類Dev

How can I merge two files while printing a given value on resulting empty fields using AWK?

分類Dev

Sed delete empty lines after a particular line number

分類Dev

How to uncomment the a specific line which contains specific text in a hocon file using bash script(sed,awk..etc)

分類Dev

Moving matching lines in a text file using sed

分類Dev

Using "sed" to uncomment lines matching a certain pattern

分類Dev

Remove empty line before a pattern using sed

分類Dev

Exclude two or more directories in bash for loop

分類Dev

awk how to set record separator as multiple consecutive empty lines or lines only include space and/or tab characters?

分類Dev

Print lines between two patterns matching a condition in awk

分類Dev

Comparing three (or more) dictionaries and finding a match if at least two are equal

分類Dev

Run into error “empty beginning of file” when read.table in R with 5 or more first empty lines

分類Dev

How to make bash built-in "read" ignore commented or empty lines?

分類Dev

Bash Using variable names in sed to insert record

分類Dev

Bash while loop search and replace using sed

分類Dev

Replacing text strings in bash using awk

Related 関連記事

  1. 1

    Why can't I sed two [or more..] empty lines to one empty line?

  2. 2

    Using sed / awk to change words between two patterns

  3. 3

    Change header using sed or awk

  4. 4

    deleting lines between rows in a text file using awk or sed

  5. 5

    Squeeze multiple empty lines with sed

  6. 6

    How to replace one line with two lines using sed in csh on BSD?

  7. 7

    Delete 'N' no lines only on the Nth occurrence of a pattern in a file using the sed/awk command

  8. 8

    Get values from beginning of file, Insert values as new columns, trim beginning lines using AWK/GAWK/SED

  9. 9

    How to remove series of lines in a file on hp unix using awk or sed or grep

  10. 10

    Text Manipulation using sed or AWK

  11. 11

    String Replacing using Sed or Awk

  12. 12

    Bash - Sed / Awk replacing string with new line

  13. 13

    sed/awk remove newline on two pattern matches

  14. 14

    Extract two variables and rewrite multiple lines with sed

  15. 15

    How can I merge two files while printing a given value on resulting empty fields using AWK?

  16. 16

    Sed delete empty lines after a particular line number

  17. 17

    How to uncomment the a specific line which contains specific text in a hocon file using bash script(sed,awk..etc)

  18. 18

    Moving matching lines in a text file using sed

  19. 19

    Using "sed" to uncomment lines matching a certain pattern

  20. 20

    Remove empty line before a pattern using sed

  21. 21

    Exclude two or more directories in bash for loop

  22. 22

    awk how to set record separator as multiple consecutive empty lines or lines only include space and/or tab characters?

  23. 23

    Print lines between two patterns matching a condition in awk

  24. 24

    Comparing three (or more) dictionaries and finding a match if at least two are equal

  25. 25

    Run into error “empty beginning of file” when read.table in R with 5 or more first empty lines

  26. 26

    How to make bash built-in "read" ignore commented or empty lines?

  27. 27

    Bash Using variable names in sed to insert record

  28. 28

    Bash while loop search and replace using sed

  29. 29

    Replacing text strings in bash using awk

ホットタグ

アーカイブ