Last active
January 6, 2016 05:09
-
-
Save KomanRudden/e04adf1d8e9a23629839 to your computer and use it in GitHub Desktop.
Grep to extract text example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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