Skip to content

Instantly share code, notes, and snippets.

@KomanRudden
Last active January 6, 2016 05:09
Show Gist options
  • Save KomanRudden/e04adf1d8e9a23629839 to your computer and use it in GitHub Desktop.
Save KomanRudden/e04adf1d8e9a23629839 to your computer and use it in GitHub Desktop.
Grep to extract text example
grep -no 'name="[^ ]*"' file.html > results.txt
In this line:
The n option will print the lines that matched the pattern. Simply for informative reasons, at first glance. Remove if you don't want it.
The o option prints only the matched text, not the entire line itself.
file.html is the path to your file.
the P option is for look arounds.
Also if you want the results saved to a file, you can pipe them by appending > results.txt:
grep -Po 'name="[^"]*"' file.html > results.txt
As below sample file results.txt will be
Koman
Test
Monday
Tuesday
Wednesday
name="Koman was here"
name="Test was here"
name="Monday is here"
name="Tuesday is tomorrow"
name="Wednesday is the middle of the week"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment