HI I have a fairly big Log File and want to see which sort of website being requested. For that I am using grep expression
grep -o 'http://[a-ZA-Z.-]*/' text.log
It gives all the urls in the documents. I want to get the only urls that look like this http://url/
URLs like this http://url/somethingAfterslash
should not be the part of output.
What you are looking for is a single string, so you may expect it to be separated from the rest by whitespaces (this is a technical term in regular expression; see below). I would try with grep -o 'http://[a-zA-Z.-]*/[[:space:]]' text.log
this matches any whitespace at the end of the word, but also tab and newlines.
In addition, some URL may contain digits or underscores, so you may have to further tune your pattern a bit more. To include these two grep -o 'http://[0-9a-zA-Z.-_]*/[[:space:]]' text.log
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.