Skip to main content
edited tags
Link
terdon
  • 53.7k
  • 14
  • 128
  • 172
Source Link
OB7
  • 193
  • 1
  • 1
  • 6

how to insert text at the beginning of each paragraph in bash

I have a file with multiple paragraphs separated by blank line. Technically they are not paragraphs just sections of text separated by blank line.

I want to number the paragraphs so to speak by inserting a number in the first line of each line following a blank line. So if my file says:

This is text.
This is more text.
Even more text!

This is text in section two.
Some more text.
You get the point...

I want to make it say:

1This is text
this is more text
Even more text!

2This is text in section two.
Some more text.
You get the point...