codehacker
codehacker

Reputation: 401

Separating paragraphs in unix

I have a file with paragraphs separated by 2 empty lines in unix. I want to copy paragraphs after searching for a word to another file. I am able to copy paragraphs but the paragraphs separators are not present so it is coming as on continuous para. My command to separate para:

awk -v RS= '/Testing/' file>>file2

Now I am getting:

Testing 
case1
Testing
case2

What I need to get

Testing 
case1


Testing
case2

Upvotes: 2

Views: 286

Answers (1)

sat
sat

Reputation: 14949

You need to set ORS (Output Record Separator) as \n\n in awk:

awk -v RS= '/Testing/' ORS='\n\n' file

Default value of ORS is \n. But, Paragraph needs \n\n.

Upvotes: 2

Related Questions