Work with awk and text blocks

Hi,
I have big files with a lot of blocks of text like below

START SECTION - Description about block
Here text (can be a lot of lines)
END  SECTION

START SECTION - Description about block
Here text (can be a lot of lines)
END  SECTION

.....etc

I need to forward each block to the separated file with unique file name (can be number of block).

Thanks
IKeystoneAsked:
Who is Participating?
 
arober11Commented:
Try:

gawk '/START SECTION/{n++}{print >"out" n ".txt" }' input_file.txt
0
 
IKeystoneAuthor Commented:
Tested in awk, working. Last question - how to add to the output files process id ?

out(n).$$.txt
0
 
arober11Commented:
Try:

gawk -v pid=$$  '/START SECTION/{n++}{print >"out" n "." pid ".txt" }' input_file.txt
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.