免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1405 | 回复: 4
打印 上一主题 下一主题

(處理完成)AWK問題 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-08-26 16:23 |只看该作者 |倒序浏览
本帖最后由 秦康 于 2010-08-27 15:47 编辑

如何可以將以下的內容以只顯示第1列和第3列 并以:分隔
-rw-r--r--  1 root root   15 Aug 20 11:56 1
-rw-r--r--  1 root root  933 Aug 23 16:09 111111111
-rw-r--r--  1 root root    8 Aug 20 11:57 2
-rw-r--r--  1 root root  441 Aug 20 15:37 a.out
-rw-r--r--  1 root root  158 Aug 24 19:45 heroes.txt
-rw-r--r--  1 root root 2689 Aug 20 12:02 passwd
-rw-r--r--  1 root root   46 Aug 20 15:41 sample_one
-rw-r--r--  1 root root    0 Aug 20 15:34 sed
-rw-r--r--  1 root root   28 Aug 20 15:47 sedlist
-rw-r--r--  1 root root  104 Aug 24 20:26 test.txt
為什麽awk -F : '{print $1,$3}' test

论坛徽章:
0
2 [报告]
发表于 2010-08-26 16:26 |只看该作者
回复 1# 秦康


    这样? awk '{print $1":"$3}' test

论坛徽章:
0
3 [报告]
发表于 2010-08-27 15:42 |只看该作者
test:~/sh# ll |awk 'BEGIN{OFS=":"}{print $1,$3}'   
total:
-rw-r--r--:root
-rw-r--r--:root
-rw-r--r--:root


test:~/sh# ll |awk -v OFS=":" '{print $1,$3}'      
total:
-rw-r--r--:root
-rw-r--r--:root
-rw-r--r--:root

论坛徽章:
0
4 [报告]
发表于 2010-08-27 15:50 |只看该作者
学习了

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
5 [报告]
发表于 2010-08-27 15:58 |只看该作者
sed 's/ /:/g' file|cut -f 1,4 -d":"
-rw-r--r--:root
-rw-r--r--:root
-rw-r--r--:root
-rw-r--r--:root
-rw-r--r--:root
-rw-r--r--:root
-rw-r--r--:root
-rw-r--r--:root
-rw-r--r--:root
-rw-r--r--:root
$ cut -f 1,4 -d" " file|sed 's/ /:/g'
-rw-r--r--:root
-rw-r--r--:root
-rw-r--r--:root
-rw-r--r--:root
-rw-r--r--:root
-rw-r--r--:root
-rw-r--r--:root
-rw-r--r--:root
-rw-r--r--:root
-rw-r--r--:root
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP