In the project, we often encounter the situation that the original table name has been replaced and needs to be replaced in batches in the script. However, it is troublesome to find out which tables are involved one by one, and it may be missed; replacing them directly on Linux may not be able to achieve good version synchronization; therefore, we can consider the combination of find and grep commands to find out the scripts that need to be modified before unified processing.
--Recursively find all files in the directory that contain this string
grep -rn "data_chushou_pay_info" /home/hadoop/nisj/automationDemand/
--find files in the current directory with filtered suffixes
grep -Rn "data_chushou_pay_info" *.py
--file in the current directory and set subdirectories that match the criteria
grep -Rn "data_chushou_pay_info" /home/hadoop/nisj/automationDemand/ *.py
--combine with the find command to filter directories and file name suffixes
find /home/hadoop/nisj/automationDemand/ -type f -name '*.py'|xargs grep -n 'data_chushou_pay_info'
In the end:
find /home/hadoop/nisj/automationDemand/ -type f -name ‘*.py’|xargs grep -n ‘data_ chushou_ pay_ [Info ‘] to meet the query requirements.
Grep options:
*: indicates all files in the current directory, or a file name
-R is a recursive search
-N is the display line number
-R find all files including subdirectories
-I ignore case
Interesting command line parameters:
grep – I pattern files: case insensitive search. Case sensitive by default
Grep – L pattern files: only the matching file names are listed, not the paths
Grep – L pattern files: lists unmatched file names
Grep – W pattern files: matches only the whole word, not part of the string (for example, matches’ magic ‘, not’ magic ‘)
Grep – C number pattern files: displays the [number] line for the matched context
Grep pattern1 | pattern2 files: displays rows that match pattern1 or pattern2
Grep pattern1 files | grep pattern2: displays rows that match both pattern1 and pattern2
Some special symbols used for search:
\ < and \ > mark the beginning and end of words respectively.
For example:
Grep man * will match “Batman”, “manic”, “man” and so on
Grep ‘< man’ * matches’ manic ‘and’ man ‘, but not’ Batman ‘
Grep ‘< man \ & gt;’ only matches’ man ‘, not other strings such as’ Batman’ or ‘manic’.
‘^’: refers to the matching string at the beginning of the line
‘$’: the matching string is at the end of the line
Read More:
- [Solved] Linux — 9 — txt files are copied from windows to Linux and read error
- How to Export All data in DataGridView to Local Excel
- How to Create Threads in Linux
- Gamit Run Error: grep SP file :bad year 2021 [How to Solve]
- Linux system service command error: Failed to allocate directory watch: Too many open files
- [Solved] Linux Error: mipsel-linux-gcc: fatal error: no input files
- Linux yum Error: All mirror URLs are not using ftp
- [Solved] Linux C++ warning: ISO C++ forbids converting a string constant to ‘char*‘ [-Wwrite-strings]
- How to Uncompress 7z files on Ubuntu, Debian, Fedora
- C#: How to Use Itextsharp to Manipulate PDF Files
- How to Fix Linux sub process /usr/bin/dpkg returned an error code (1)
- How to Download APK Files from Google Play Store
- Linux: How to Solve sudo operate Error
- Linux: How to Fix undefined reference to `itoa’
- linux(aarch64): How to Fix kettle Startup Error Issue
- Linux: How to Solve Rabbitmq Plug-in Install Error
- Linux: How to Solve vim ~/.bashrc Execute Error
- How to Solve Linux Error: -bash: unzip: command not found
- Linux: How to Solve pyperclip Module Error
- How to Fix Ubuntu(Linux) mount error(22)