1. Double quotes and single quotes When entering string arguments in the g r e p command, it is best to enclose them in double quotes. For example: “m y s t r i n g”. There are two reasons for this, one is to prevent misunderstanding as a shell command, and the other is to find a string of multiple words, for example: "jet plane”, if you do not enclose it in double quotes, then the word The plane will be mistaken for a file, and the result of the query will return an error message that the file does not exist. Double quotes should also be used when calling variables, such as: g r e p“$ M Y VA R” filename, if not, no result will be returned. Single quotes should be used when calling pattern matching. [root@mypc ]# echo `grep 123 111.txt` (#Note is anti-single quote) 2. The commonly used g r e p options are: -c Output only the count of matching lines. -i is not case sensitive (only for single characters). -h Does not display the file name when querying multiple files. -l When querying multiple files, only the file name containing the matching characters is output. -n displays matching lines and line numbers. -s Does not display error messages that do not exist or have no matching text. -v Displays all lines that do not contain matching text. 3. Special ——Query in multiple files $grep "sort"*.doc (#Find the string in all .doc files in the current directory<quo;sor t”)
$ grep "sort it" * (#or query the word in all files <;sort it”) The next example is to query in a single file. 4. The line matches $grep -c "48" data. f$ 4 (#grep returns the number 4, meaning there are 4 lines containing the string “4 8”.) $ grep "48" data.f (#displays 4 lines of text containing "4 8” string") 5. Display the number of rows and rows that match the matching pattern: [root@mypc oid2000]# grep -n 1234 111.txt 1:12343:1234ab6. Exact match [root@mypc oid2000]# grep "1234\\>" 111.txt 12347. Query blank lines to query for lines that begin or end with a condition. Use ^ and $ together to query empty lines. Use the -n parameter to display the actual number of lines [root@mypc oid2000]# grep -n "^$" 111.txt (return result 2: #describe the second line is blank) [root@mypc oid2000]# grep - n "^abc" 111.txt (#Query the line starting with abc)[root@mypc oid2000]# grep -n "abc$" 111.txt (#Query the line ending with abc) 8. Match special Character, query for characters with special meaning, such as $ . ' " * [] ^
Many media and experts believe that Linux believes that Linux is more secure than Windows. However,
This article describes the solution when encountering is not in the sudoers file during Linux use. W
redhat-5.4 U disk installation process Preparation: FbinstTool.exe-softwareredhat-5.4-boot.fba-boot
Format: printf("\\033[word background color; font color m string \\033[0m" ); printf("
Install and configure FTP service in CentOS
How to set up SSH login under Linux? Email reminder notification
Hard disk bad track detection tutorial under Linux
Detailed dns settings under Linux
Seven highly damaging Linux system commands
Nginx one-click installation script under Centos
Linux graphical interface and text interface switching operation method
Install the Linux operating system through the image file on the hard disk
The configuration of the news reader under Linux
How to use the capability feature to enhance the security of Linux systems
Win7 how to restore the default font
How does Win10 add hibernation option on the shutdown button?
Win10 preview version 10061 lock screen interface black screen solution
Windows 7 is watching! Virus threats hit
How to open the Win7 system taskbar?
The difference between Win7 system upgrade installation and new installation
Win7 system prompts the windows main process rundll32 has stopped working how to do
MorphVOX Pro Voice Changer Tutorial
Master's tricks to uninstall dual systems
Win7 prompts "The display driver has stopped responding and has been restored" processing method