regexp
ERegExp
Wildcard/Glob
man 7 glob
glob - globbing pathnames. glob is a shell built-in.
主要用于匹配带有通配符的文件路径。其匹配字符串的能力比正则表达式弱。
它最初是贝尔实验室 Unix 系统上的一个名叫 glob 的命令(glob 是 global 的缩写),用于展开命令行中的通配符。后来系统提供了该功能的 C 语言库函数glob(),知名的 shell 解释器就使用了该接口,shell 脚本和命令行中使用的 glob 模式匹配功能便源自于此。——见博客。
{}
严格来讲不属于glob的范畴,其在shell表示一个分组,见:All about {Curly Braces} in Bash。
sed
awk
格式
1 | awk -F' *|:' '/LISTEN/{print $2}' |
其中,-F
表示分隔符; *|:
是一个正则表达式,表示以”一个或多个空格”或”:”作为分隔符;
再其后的//
中是另一个正则表达式,用于匹配文本;{}
中是action。
条件判断
if-else in awk
use AND and OR in an awk program
1 | awk '{if ($1 > 49151 && $1 < 65536) {print $1} }' |
等价于
1 | awk '$1 > 49151 && $1 < 65536' |
BEGIN/END
In AWK, BEGIN
and END
are special patterns that allow you to execute code before processing the input (BEGIN
) or after processing all the input (END
).
- The
BEGIN
block is executed once at the beginning of the AWK program and it is typically used for initializing variables or performing setup tasks. - The
END
block is executed once after processing all input, and it is commonly used for final caclucations, summaries, or printing results.
Special symbols
$
用于引用field,例如$1
代表第一个field(典型来说是第一列)。NF
表示number of filed,假设一共有7列,那么$NF
与$7
等价。
grep
Example
- 找出一个未使用的port
1 | # "$$"是为了转义"$" |
1 | # 从1025开始找出已经存在的端口,如果相邻端口的gap大于1,则返回“当前端口号+1” |
1 | #这不是正则表达式 |