sed 行编辑命令
s 替代
i 插入
a 附加
d 删除全部匹配的行
D 删除首次匹配的行
打印1到4行
[root@localhost test]# sed -n '1,4p' test.txt
byte_order little
block_size 8192
data_path data
lob_path lob
替换:
[root@localhost test]# sed 's/lob/*****/g' test.txt
byte_order little
block_size 8192
data_path data
*****_path *****
charset_name ZHS16GBK
ncharset_name AL32UTF8
output_format text
*****_storage file
c*****_byte_order little
trace_level 1
delimiter |
从第5行开始替换:
[root@localhost test]# sed '5,$s/lob/***/g' test.txt
byte_order little
block_size 8192
data_path data
lob_path lob
charset_name ZHS16GBK
ncharset_name AL32UTF8
output_format text
***_storage file
c***_byte_order little
trace_level 1
delimiter |
打印包含lob的行:
[root@localhost test]# sed -n '/lob/'p test.txt
lob_path lob
lob_storage file
clob_byte_order little
[root@localhost test]#
打印行号:
[root@localhost test]#
[root@localhost test]# sed = test.txt
1
byte_order little
2
block_size 8192
3
data_path data
4
lob_path lob
5
charset_name ZHS16GBK
6
ncharset_name AL32UTF8
7
output_format text
8
lob_storage file
9
clob_byte_order little
10
trace_level 1
11
delimiter |
12
13
删除文本,打印余下的文本:
[root@localhost test]# sed '1,5d' test.txt
ncharset_name AL32UTF8
output_format text
lob_storage file
clob_byte_order little
trace_level 1
delimiter |
删除含有lob的行:
[root@localhost test]# sed /lob/d test.txt
byte_order little
block_size 8192
data_path data
charset_name ZHS16GBK
ncharset_name AL32UTF8
output_format text
trace_level 1
delimiter |
删除首次出行81的行
[root@localhost test]# sed '/81/D' test.txt
byte_order little
data_path data
lob_path lob
charset_name ZHS16GBK
ncharset_name AL32UTF8
output_format text
lob_storage file
clob_byte_order little
trace_level 1
delimiter |
批量修改文件名:
把abc开头的文件修改为def
# ls /u01/change|grep abc|sed -e 's/abc\(.*\)/mv & def\1/'|sh
awk 可以处理列,也可以处理行,可以定位到第几行,第几列,暂时列出awk,之后会详细的学习。
打印行号和第二列:
[root@localhost test]# awk '{print NR,$2}' test.txt
1 little
2 8192
3 data
4 lob
5 ZHS16GBK
6 AL32UTF8
7 text
8 file
9 little
10 1
11 |
12
13