Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use sed to remove the rest of a line after: HTTP1.1" 200

I can't figure out how to get sed to understand I want that whole thing as a string to match, including the double quote and the space.

An example for good measure, I want to turn:

"GET /images/loading.gif HTTP/1.1" 200 10819 "https://...


"GET /images/loading.gif HTTP/1.1" 200
share|improve this question
Well a lot of searching didn't help me find it. Do you feel comments like this are helping the community? – erds Feb 19 at 18:31
Unfortunately as per you're example, you've fundamentally not understood my question. The key information I'd needed was how to sed the spaces. What it turned out to be was that i was also flipping the order for use of my quotes and double quotes. – erds Mar 8 at 17:40
Comments removed buddy, what a shame you could not receive or accept multiple opinions. Have a nice day. – tachomi Mar 8 at 17:49
up vote 5 down vote accepted

You have to quote strings with spaces when you use sed (or most other tools) from the commandline. And since you already use the double quote, you have to go for single quotes:

echo '"GET /images/loading.gif HTTP/1.1" 200 10819 "https://...' | \
     sed 's|HTTP/1.1" 200.*|HTTP/1.1" 200|'


"GET /images/loading.gif HTTP/1.1" 200
share|improve this answer

With GNU grep:

| grep -o '.*HTTP/1\.1" 200'

With GNU sed:

| sed -r 's/(.*HTTP\/1\.1" 200).*/\1/'
share|improve this answer
Is the (?= ) lookahead necessary? I think you can remove it and -P. – Digital Trauma Feb 13 at 0:20
Yes, thank you. I've updated my answer. – Cyrus Feb 13 at 6:59

If you just append a newline delimiter after your matched string you can Print only so much of pattern space without having to modify it overmuch. This can usually even work when pattern space contains bytes which are not parts of a character.

sed -n 's|HTTP/1.0” 200|&\n|;P' <in >out

note: portably you'll want to use a literal newline character in place of the n used above, though it does work as written in a GNU sed

share|improve this answer

Your Answer


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.