Copy everything before the first blank line

6

I have a file with several blocks of text separated by a blank line. Ex.:

block1
block1

block2

block3
block3

I need a solution with sed, awk or perl that finds the first blank line and redirects the previous block to another file and so on until the end of the file.

I have this command in sed that locates the first block, but not the rest: sed -e '/./!Q'

Can anyone help me?

    
asked by anonymous 11.12.2015 / 19:34

2 answers

2

The following command creates files "output1", "output2", etc., with each block.

awk -v RS="" '{print > "output" NR }' input.txt

Explanation:

  • % with% records separated by one or more blank lines
  • RS="" write block in output + record number.

Was this what you wanted?

    
18.12.2015 / 16:56
0

I do not know if I understand correctly, but if your goal is to remove the blank lines, you can use the following command:

sed '/^\s*$/d'
    
11.12.2015 / 20:05