免费注册 查看新帖 |

Chinaunix

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

[文本处理] 将txt文件装换成csv文件 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-01-05 12:37 |显示全部楼层 |倒序浏览
在Llinux 下, 本人需将以下的文本文件 a.txt 转换成csv文件,第一,第二列,第三列mapping csv的第一第二第三列,第三列没有固定的格式。

tdecom34        /config/TDAMINFOS.conf        /td/logs/httpd/tda.soc.tdgroup.com_error_log.*
tdecom34        /config/TDAMINFOS.conf        /td/logs/httpd/ihs_BBPGen34_httpd_plugin.log
tdecom34        /config/TDAMINFOS.fmt        (SSL0221E: SSL Handshake Failed)
tdecom34        /config/TDAMINFOS.fmt        (Marking)(?:.*)(down)
tdecom34        /config/OVN.fmt                        (Failed to execute the transaction to)(.*)(ecawap)(.*)(_node_OvationWS)
tdecom34        /config/BSL.fmt                        (com.ctc.wstx.exc.WstxUnexpectedCharException)
tdecom34        /config/BBPIHS.fmt                (IHS instance(s) clients setting has reached 1000 (MAX) threads)
ecswap33        /config/WFA.conf                /td/logs/WebLogs/WebFundsAdmin_33/System-ecswap33*.log
ecswap33        /config/WFA_tdsystem.fmt        (Error code: TD.SQL.4060 : SQLException - problems executing)
ecswap33        /config/WFA_tdsystem.fmt        Error code: TD.SQL.0 : The TCP\/IP connection to the host \*,port 3341 has failed., p


先谢谢了。

论坛徽章:
0
2 [报告]
发表于 2014-01-06 00:21 |显示全部楼层
本帖最后由 fzhcl 于 2014-01-06 00:27 编辑

回复 3# elu_ligao

两种代码都有同样的问题:最后一行变成多个列了。

ecswap33        /config/WFA_tdsystem.fmt        Error code: TD.SQL.0 : The TCP\/IP connection to the host \*        port 3341  has failed.         p

谢谢

论坛徽章:
0
3 [报告]
发表于 2014-01-06 00:27 |显示全部楼层
回复 2# Shell_HAT


这个非常符合我的要求,谢谢

   

论坛徽章:
0
4 [报告]
发表于 2014-01-06 00:47 |显示全部楼层
elu_ligao 发表于 2014-01-05 14:25
回复 1# fzhcl


参照Shell_HAT的code, 给$3 加上“” 就好了,
awk '{printf $1","$2",""\"";for(i=3;i<=NF;++i)printf $i;print a"\""}'
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP