0

I have the following pattern of a string:

"METHOD URL VERSION"

example "GET /someurl/resource.html HTTP/1.1"

How can I get the url from this string with grep.

I did the following(assuming that string contains in f.txt)

cat f.txt | grep -P '[^(( )|(\")|(HTTP\/\d\.\d)|(GET)|(POST))]+' -o

but it gives me such an output

someurl
resource
html

How can I retrieve /someurl/resource.html ?

1 Answer 1

1

This should do it:

grep -o "\/.* "

ok, if you have the pattern:

"somestring1withoutspaces somestring2withoutspaces somestring3withoutspaces" then both of these works:

grep -o " .* " 
awk '{print $2}'
Sign up to request clarification or add additional context in comments.

1 Comment

url can start with http and with www or simply the name of the file like image.png

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.