Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash split file on double newline

Tags:

bash

I have some files with content that change from file to file. Each file have 2 sections of lines separated by a blank line. I never know how many lines or characters there are in either section.

The file can look something like this.

This is a file
with some text

and some more text

This code only gives the first line from each section.

awk 'BEGIN {RS="\n\n"; FS="\n";} {print $1 }' file

I need each section split up to work with.

like image 536
Jan Avatar asked Sep 03 '26 13:09

Jan


1 Answers

Prints first part: sed '/^$/q' test.txt

Prints second part: sed '1,/^$/d' test.txt

like image 114
ulicar Avatar answered Sep 05 '26 13:09

ulicar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!