You're viewing a comment by Piyush Patel and its responses.

Piyush Patel Permalink
July 05, 2014, 06:20

Dear Sir,

I am not fluent in sed but it is very easy to use. Now I have Text file with 7 different pages/sections and there is blankline after each page/section. Now Suppose if I want to get only second page/section. How can I use sed to get the specific section?

Comment Responses

Anirudh Permalink
February 01, 2016, 16:01
sed -e '
# initialize paragraph counter to 1
1{x;s/.*/./;x}

# each paragraph handled here
/./,/^$/{
   /./{H;d;}
# stash the present line ofthe current para to hold space

   # interrogate the paragraph counter
   # a) if success, then print para and quit promptly
   # b) if no, then increment counter and clear hold space

   x
      /^[.]\{3\}\n/{
         # SUCCESS
         s///; q
      }
      # NOT THERE YET...
      s/\n.*//
      s/^/./
   x
}

# non-interesting lines
d
'

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "cdrom_95": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.