Posts

Showing posts with the label Regular Expressions

Common Examples of Using gsed on FreeBSD

gsed [-nefir] [action] Options and parameters: -n :  Use silent mode. In general gsed usage, all data from STDIN will generally be listed on the screen. But if the -n parameter is added, only the line (or action) that has been specially processed by gsed will be listed . -e command :  Edit gsed actions directly in the command line mode. -f   command_file :  Write the gsed action directly in a file, -f command_file can execute the gsed action in command_file . -i   : Modify the content of the read file directly instead of outputting it on the screen. -r :  The action of gsed supports the grammar of extended formal expressions. (The default is basic regular expressions grammar) . Action description: [n1[,n2]]function   n1, n2   :  It doesn’t necessarily exist. It generally means "choose the number of lines to perform an action". For example, if my action needs to be performed between 10 and 20 lines, then "10,20[action behavior]". ...

Regular Expressions Special Symbols

[:alnum:]   Represents English uppercase and lowercase letters and numbers, and 0-9, A-Z, a-z. [:alpha:]   Represents any English uppercase and lowercase letters, as well as A-Z, a-z. [:blank:]   Represents both the space key and the [Tab] key . [:cntrl:]   Represents the control keys on the keyboard, including CR, LF, Tab, Del... etc. [:digit:]   Represents only numbers, that is, 0-9 . [:graph:]   All keys except blank characters (space key and [Tab] key) . [:lower:]   Represents lowercase characters, i.e. a-z . [:print:]   Represents any character that can be printed. [:punct:]   Represents punctuation symbol, that is: "'?!;: # $... [:upper:]   Represents uppercase characters, which is A-Z. [:space:]   Any characters that will produce blanks, including blank keys, [Tab], CR, etc. [:xdigit:]   Represents a hexadecimal number type, so it includes: 0-9, A-F, a-f numbers and characters.

Commonly Used Regular Expressions

Search for a specific string Use dmesg to list the core information and then use grep to find out which line contains " tap" , and to color the captured keywords, and add the line number to indicate: dmesg -a | grep -n --color=auto 'tap' The first two lines and the last three lines of the line where the keyword is located are also captured and displayed: dmesg -a | grep -n -A3 -B2 --color=auto 'tap'   dmesg is a command on most Unix-like operating systems that prints the message buffer of the kernel. The output includes messages produced by the device drivers.   Suppose we want to get the specific string "abc" from the file just now, the easiest way is like this:   grep -n 'abc' regular_express.txt  -n   Show line number. I want to display the line where the string abc is a specific ignoring case: grep -in 'abc' regular_express.txt -i   Ignore case.   What we want is that the line does not have the string "abc" to be d...