Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Use the fgrep command of linux to search for text strings for files

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you the use of linux's fgrep command to search for text strings for files. I hope you will gain a lot after reading this article. Let's discuss it together.

The function of the fgrep command is to search for lines that match patterns in the input file specified by the file parameter (the default is standard input). The fgrep command specifically searches for Pattern parameters, which are fixed strings. If you specify more than one file in the File parameter, the fgrep command displays the file that contains the matching lines.

The fgrep command works differently from the grep and egrep commands because it searches for strings rather than patterns that match expressions. The fgrep command uses a fast compression algorithm. Strings such as $, *, [, |, (,) and\ are interpreted literally by the fgrep command. These characters are not interpreted as regular expressions.

If no file is specified, the fgrep command assumes standard input. In general, every line found is copied to standard output. If there is more than one input file, the file name is printed before each line found.

Fgrep has the following related properties:

The fgrep command is the same as the grep command with the-F flag, but the error and usage messages are different-the s flag function is also different. Each line is limited to 2048 bytes. Paragraphs (under the-p flag) are currently limited to 5000 characters in length. Do not run the grep command in a specific file, as it can produce unpredictable results. The input line cannot contain empty characters. The input file should end with a newline character. Although many flags can be specified at the same time, some flags override the rest. For example, if you specify both-l and-n, only the file name is written to the standard output.

Syntax format: fgrep [parameters]

Common parameters:

Reference example

Search for the string strcpy in all files ending with a .c string in the current directory:

[root@linuxcool] # fgrep strcpy * .c

Search for files in the current directory that end with .c, and then display the file name that contains the strcpy string:

[root@linuxcool] # fgrep-l strcpy * .c

Match the line with a:

[root@linuxcool ~] # cat linuxcool.sh | fgrep a has finished reading this article. I believe you have some understanding of using linux's fgrep command to search for text strings for documents. Want to know more about it. Welcome to follow the industry information channel. Thank you for reading!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report