I
I
IceCream442018-10-19 14:11:33
linux
IceCream44, 2018-10-19 14:11:33

How to find lines containing url using regular expressions in linux?

How to find lines containing url using regular expressions in linux?
With the grep command
I tried like this grep "[http\:]\+[a-zA-z0-9]+\.[az]\{2,4\}" /etc/
writes the wrong range

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Softer, 2018-10-19
@IceCream44

grep -rE 'https?://[a-zA-Z0-9][\.a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,}' /etc

P
pfg21, 2018-10-19
@pfg21

urlregex.com
learn to ask the right questions to Yandex

A
Alexey Ukolov, 2018-10-19
@alexey-m-ukolov

Of course, incorrect - it should be like this:[a-zA-Z0-9]

K
Karpion, 2018-10-20
@Karpion

Well, for starters - this pattern cannot be enclosed in double quotes, apostrophes are needed here - because quotes do not escape backslashes.
Then the entry "[http\:]" raises suspicion - probably, the whole string "http" is needed here, and not "any of the letters".
About "Az" they said here.
"/etc/" is a search in the body of the directory, i.e. among filenames (rather than in file bodies).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question