In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Preface
In the Linux system to search and find the contents of the file, generally the most commonly used is the grep command, in addition, there is an egrep command, while the vi command also supports file content retrieval. Let's take a look at the details of how Linux uses the grep command to retrieve the contents of a file.
The methods are as follows:
1. Search for whether a file contains a string
Command format: grep "found string" filename1
For example:
Grep "0101034175" / data/transaction.20170118.log
2. Retrieve a string in multiple files
Command format:
Grep "found string t" filename1 filename2 filename3... grep "found string" * .log
3. Display the number of lines of the retrieved content in the file. You can use the parameter-n
Command format: grep-n "found string" * .log
4. The case problem needs to be ignored when searching, and the parameter "- I" can be used.
Command format: grep-I "found string" * .log
5. Find lines that do not match the specified string from the contents of the file
Command format: grep-v "found string" file name
6. Search and find the number of matching rows:
Command format:
Grep-c "found string" file name "grep" found string "file name | wc-l
7. Recursively search for all files in a directory and subdirectories
Command format: grep-r "found string" file directory
8. Get which files contain the contents of the search, and list the file names
Command format: grep-H-r "found string" file directory | cut-d:-F1 [| uniq]
For example:
Grep-H-r "v\ $temp_space_header" / u01/app/Oracle/product/11.1.0/dbhome_1/rdbms/admin/ | cut-d:-f1grep-H-r "v\ $temp_space_header" / u01/app/oracle/product/11.1.0/dbhome_1/rdbms/admin/ | cut-d:-F1 | uniq
9. Get the content that matches the entire search character
Command format: grep-w "found string" filename
10. The combination of grep command and find command to realize joint retrieval.
Command format: find. -name'* .sql'- exec grep-I 'retrieved content' {}\;-print
For example:
Find. -name'* .SQL'- exec grep-I'v\ $temp_space_header' {}\;-print
The difference between Linux grep and find
These are two different commands about grep:
Grep command is a powerful text search tool in Linux system. It can use regular expressions to search text and print matching lines. The full name of grep is Global Regular Expression Print, which represents the global regular expression version, and its permission is for all users.
And find under linux (for more information, please see here: https://www.jb51.net/article/108198.htm)
Function: search for files in the directory structure and perform specified operations. This command provides quite a number of search criteria and is very powerful.
Syntax: find start directory search condition operation
Description: the find command starts from the specified starting directory, recursively searches its subdirectories, finds files that meet the search criteria and takes relevant actions on them.
So to put it simply, grep is a line to find matching criteria, and find is a file to search for matching criteria.
Summary
The above is the whole content of this article, I hope that the content of this article has a certain reference and learning value for your study or work, if you have any questions, you can leave a message and exchange, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.