Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm going to submit form using cURL, where some of the contents is come from other file, selected using sed

If param1 is line matching pattern from other file using sed, below command will works fine:

curl -d param1="$(sed -n '/matchpattern/p' file.txt)" -d param2=value2 http://example.com/submit

Now, go to the problem. I want show only text between 2 matching pattern excluding the matching pattern itself.

Lets say file.txt contains:

Bla bla bla
firstmatch
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.
secondmatch
The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English.

Currently, lots of "beetween 2 matching pattern" sed command won't remove firstmatch and secondmatch.

I want the result become:

It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.
share|improve this question

2 Answers 2

Here is one way you could do it:

sed '1,/firstmatch/d;/secondmatch/,$d' 

Explained: From the first line to the line matching firstmatch, delete. From the line matching secondmatch to the last line, delete.

share|improve this answer

In awk:

awk '
  $1 == "secondmatch" {print_me = 0}
  print_me {print}
  $1 == "firstmatch {print_me = 1}
'
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.