Hello, I have a mysql dump. With grep, I try to find the strings that match the given regular expression. For example grep --color "youtube.com/embed" dump.sql

But the entire database dump is written in one line. And the dump is very large, and it displays almost everything. I try egrep -o --color "youtube.com/embed" dump.sql , but it only displays "youtube.com/embed". How can I make it possible to display youtube.com/embed and more adjacent characters. for example "src =" // www. youtube.com/embed / ZGrvJ3m4kS8 "fra"? Thank you in advance.

    1 answer 1

    And the places where youtube meets always look like src="..." ? If so, you can try the following: grep -Po 'src=.*?youtube.com/embed.*?"' .

    If only url is interested, you can do this: grep -Po '\byoutube.com/embed/[a-zA-Z0-9]*' is if the string after embed is always alphanumeric

    Update

    So why bother? If the string after embed is always alphanumeric, you can use the following: egrep -o 'youtube.com/embed/[a-zA-Z0-9]+' - also displays each link on a separate line, but the option with grep -P I like more

    • grep -Po 'src =. *? youtube.com/embed.*? "'. In this case, it also prints the entire line. And one line is equivalent to 1000 lines. I tried this way egrep -o --color" src = \\ \\\ "// www.youtube.com/embed.{1,100}" grow.sql - REBOST
    • @vitaan, so-with ... What version of grep`a? What distribution? I checked in a few - everything works as it should. Are you sure you use grep with the -P key? egrep (without the -P key) just prints the entire line (grep displays each link on a separate line) - BOPOH
    • Thanks for the answer. But I did a bit different way egrep -o --color ". {100} www.youtube.com/embed. {100}" grow.sql now displays 100 characters before the pattern and after - REBOST
    • @vitaan, so why display too much? If the string after embed is always alphanumeric, you can use the following: egrep -o 'youtube.com/embed/[a-zA-Z0-9]+' - also displays each link on a separate line, but the option with grep -P I like it more - BOPOH