SeleniumBase/help_docs/useful_grep_commands.md

38 lines
1.2 KiB
Markdown
Raw Normal View History

2022-11-05 13:27:22 +08:00
<!-- SeleniumBase Docs -->
2022-08-06 06:27:38 +08:00
## Useful grep commands
2022-02-04 11:16:49 +08:00
There are several useful **grep** commands for helping you find and/or replace text in multiple files. Examples:
#### List all files containing ``self.get_new_driver(``, ignoring ".pyc" files, from the current directory:
``grep -rl "self.get_new_driver(" * --exclude=\*.pyc``
OR
``grep -rl * -e "self.get_new_driver(" --exclude=\*.pyc``
2022-08-06 06:27:38 +08:00
To only search ``.py`` files, use ``--include=\*.py``:
``grep -rl "self.get_new_driver(" * --include=\*.py``
2022-02-04 11:16:49 +08:00
--------
2022-02-06 12:04:48 +08:00
#### Replace all occurrences of "foo_abc" with "bar_xyz" on Linux, for Python files from the current directory:
2022-02-04 11:16:49 +08:00
2022-02-06 12:04:48 +08:00
``sed -i 's/foo_abc/bar_xyz/g' *.py``
2022-02-04 11:16:49 +08:00
2022-02-06 12:04:48 +08:00
#### Replace all occurrences of "foo_abc" with "bar_xyz" on macOS, for Python files from the current directory:
2022-02-04 11:16:49 +08:00
2022-02-06 12:04:48 +08:00
``sed -i '' 's/foo_abc/bar_xyz/g' *.py``
2022-02-04 11:16:49 +08:00
--------
#### Find all chromedriver processes (this combines ``ps`` with ``grep``):
``ps -ef |grep chromedriver``
--------
#### References:
* https://stackoverflow.com/questions/16956810/how-do-i-find-all-files-containing-specific-text-on-linux
* https://stackoverflow.com/questions/11392478/how-to-replace-a-string-in-multiple-files-in-linux-command-line/20721292#20721292