linux shell cut按列切分文件

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

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值