分享

linux shell cut按列切分文件

 昵称33885179 2017-01-19
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

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多