linux cut按列切分文件
-f:选择的哪些列
--complement 补集运算
例:
[root@localhost test]# cat student.data
NO Name Mark
1 lufubo 98
2 cbiao 88
[root@localhost test]# cut -f2,3 student.data
Name Mark
lufubo 98
cbiao 88
[root@localhost test]# cut -f2,3 --complement student.data
NO
1
2
如若要指定字段的定界符,使用-d选项:
[root@localhost test]# cat student.data
NO; Name; Mark
1; lufubo; 98
2; cbiao; 88
[root@localhost test]# cut -f2 -d ";" student.data
Name
lufubo
cbiao
cut命令还可将一串字符作为列来显示:
N-:从第N个字节 ,字符到行尾
N-M:从第N-M个字节
-M:从1-M个字节
-b:表示字节
-c:表示字符
-f:表示定义字段
例 :
[root@localhost test]# cat data.txt
asdfghjkl
asdfghjkl
asdfghjkl
[root@localhost test]# cut -c1-5 data.txt
asdfg
asdfg
asdfg
[root@localhost test]# cut -c-2 data.txt
as
as
as
[root@localhost test]# cut -b5 data.txt
g
g
g
sed表达式常用单引号,不过也可用双引号,双引号会通过对表达式求值来对其进行扩展。当我们想在sed 表达式中使用一些变量字符时,双引号就很有用了:
[root@localhost test]# test=hello
[root@localhost test]# echo hello world | sed "s/$test/HELLO/"
HELLO world