免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2782 | 回复: 6

[已解决]cut分割符疑问 [复制链接]

论坛徽章:
0
发表于 2008-06-11 09:48 |显示全部楼层
不管是man还是google都说cut默认的分割符是空格或者tab
但是怎么用tab为分割符取段呢?
这样根本不行

  1. $ ps aux> ps.txt
  2. $ cut -f1 ps.txt
复制代码


以空格分割的话这样可以

  1. $ cut -d' ' -f1 ps.txt
复制代码


但是怎么都没法以tab分割,还请指教,谢谢!

[ 本帖最后由 Ksharp 于 2008-6-11 10:06 编辑 ]

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
发表于 2008-06-11 09:53 |显示全部楼层
ps aux的结果里有Tab么?

论坛徽章:
0
发表于 2008-06-11 10:00 |显示全部楼层
一语点醒我,看来是有些误解了
再请问一下,如果是以空白分割符又该怎么写呢?
就像awk那样

论坛徽章:
8
摩羯座
日期:2014-11-26 18:59:452015亚冠之浦和红钻
日期:2015-06-23 19:10:532015亚冠之西悉尼流浪者
日期:2015-08-21 08:40:5815-16赛季CBA联赛之山东
日期:2016-01-31 18:25:0515-16赛季CBA联赛之四川
日期:2016-02-16 16:08:30程序设计版块每日发帖之星
日期:2016-06-29 06:20:002017金鸡报晓
日期:2017-01-10 15:19:5615-16赛季CBA联赛之佛山
日期:2017-02-27 20:41:19
发表于 2008-06-11 10:02 |显示全部楼层
cut只能指定一个字符为分割符

论坛徽章:
0
发表于 2008-06-11 10:04 |显示全部楼层
另外 貌似默认只是tab,没有空格

  1. $ cat test

  2. yes        this is a tab
  3. no  i don't think so
复制代码


  1. $ cut -f1 test

  2. yes
  3. no  i don't think so
复制代码

论坛徽章:
0
发表于 2008-06-11 10:05 |显示全部楼层

回复 #4 waker 的帖子

嗯 明白了 谢谢

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
发表于 2008-06-11 10:19 |显示全部楼层

回复 #5 Ksharp 的帖子

cut cuts out (extracts) columns from a table or fields from each line
in a file; in data base parlance, it implements the projection of a
relation.  Fields as specified by list can be fixed length (defined in
terms of character or byte position in a line when using the -c or -b
option), or the length can vary from line to line and be marked with a
field delimiter character such as the tab character (when using the -f
option).
  cut can be used as a filter; if no files are given, the
standard input is used.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP