1.递归比较两个目录下的所有文件:
$ diff -ruNa A B
2.目录文件中,将所有的motfcc替换成dtsec:
grep -l motfcc -r ./ | xargs sed -i 's/motfcc/dtsec/g'
3.
01
#!/bin/sh
02 Upstreamif_ori = 'fei0'
03 Upstreamif_new = 'dtsec4'
04 Port1_ori = 'gei0'
05 Port1_new = 'dtsec0'
06 Port2_ori = 'gei1'
07 Port2_new = 'dtsec1'
08
09 grep -l gei -r ./ | xargs sed -i -e "s/\\\"$Port1_ori\\\"/\\\"$Port1_new\\\"/g" \
10 -e "s/\\\"$Port2_ori\\\"/\\\"$Port2_new\\\"/g"
11
12 grep -l fei -r ./ | xargs sed -i -e "s/\\\\\"$Upstreamif_ori\\\\\"/\\\\\"$Upstreamif_new\\\\\"/g"
02 Upstreamif_ori = 'fei0'
03 Upstreamif_new = 'dtsec4'
04 Port1_ori = 'gei0'
05 Port1_new = 'dtsec0'
06 Port2_ori = 'gei1'
07 Port2_new = 'dtsec1'
08
09 grep -l gei -r ./ | xargs sed -i -e "s/\\\"$Port1_ori\\\"/\\\"$Port1_new\\\"/g" \
10 -e "s/\\\"$Port2_ori\\\"/\\\"$Port2_new\\\"/g"
11
12 grep -l fei -r ./ | xargs sed -i -e "s/\\\\\"$Upstreamif_ori\\\\\"/\\\\\"$Upstreamif_new\\\\\"/g"
\\\"$Port1_ori\\\" 会匹配 "gei0"
第一遍转义:shell 先做一遍 \ 转义,\"gei0\"
第二遍转义:正则表达式将 \"gei0\" 匹配成 "gei0"
\\\\\"$Port1_ori\\\\\" 会匹配 \"gei0\"
第一遍转义:shell 先做一遍 \ 转义,\\"gei0\\"
第二遍转义:正则表达式将\ \"gei0\\" 匹配成 \"gei0\"
4. 从文件中,提取 '(' 和 ‘/' 之间的数字
1
#!/bin/sh
2 File = $*
3 sed -i -e '/^$/d' \
4 -e 's/^.*(//' \
5 -e 's/\/.*$//' $File
2 File = $*
3 sed -i -e '/^$/d' \
4 -e 's/^.*(//' \
5 -e 's/\/.*$//' $File
5. sed -e '/./{H;$!d;}' -e 'x;/INTERPEAK_COPYRIGHT_STRING/!d;' ipradius_config.c
显示包含 INTERPEAK_COPYRIGHT_STRING 的段落,段落之间用空行分隔。