免费注册 查看新帖 |

Chinaunix

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

如何批量追加日期 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-08-23 08:43 |只看该作者 |倒序浏览
文本如下:

"张三",37559924,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
"里斯",37530215,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
"王五",37464466,78.19,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,
"赵六",37490489,402.10,27000.00,0.00,157000.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,22750.00,


如何在第二个字段后面批量追加日期?日期格式20100823

如何把文本每行最后那个,去掉?


处理后格式如下

"张三",37559924,20100823,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00
"里斯",37530215,20100823,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00
"王五",37464466,20100823,78.19,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00
"赵六",37490489,20100823,402.10,27000.00,0.00,157000.00,0.00,0.00,0.00,0.00,0.00,0.00,0.00,22750.00


谢谢!

论坛徽章:
23
15-16赛季CBA联赛之吉林
日期:2017-12-21 16:39:27白羊座
日期:2014-10-27 11:14:37申猴
日期:2014-10-23 08:36:23金牛座
日期:2014-09-30 08:26:49午马
日期:2014-09-29 09:40:16射手座
日期:2014-11-25 08:56:112015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:49:0315-16赛季CBA联赛之山东
日期:2017-12-21 16:39:1915-16赛季CBA联赛之广东
日期:2016-01-19 13:33:372015亚冠之山东鲁能
日期:2015-10-13 09:39:062015亚冠之西悉尼流浪者
日期:2015-09-21 08:27:57
2 [报告]
发表于 2010-08-23 08:54 |只看该作者
sed 's/,/,20100823,/2;s/,$//' urfile

求职 : 技术支持/维
论坛徽章:
0
3 [报告]
发表于 2010-08-23 09:05 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
4 [报告]
发表于 2010-08-23 09:07 |只看该作者
  1. sed 's/\([^,]\+,[^,]\+,\)/&20100823,/' urfile
复制代码

论坛徽章:
0
5 [报告]
发表于 2010-08-23 09:09 |只看该作者
回复 2# ly5066113
  1. 's/,/,20100823,/2‘
复制代码
这个为什么 最后面会多出一点呢 , 不是只替换第二个 , 吗~!

论坛徽章:
0
6 [报告]
发表于 2010-08-23 09:10 |只看该作者
谢谢,试一下!

论坛徽章:
15
2015年辞旧岁徽章
日期:2015-03-03 16:54:15双鱼座
日期:2015-01-15 17:29:44午马
日期:2015-01-06 17:06:51子鼠
日期:2014-11-24 10:11:13寅虎
日期:2014-08-18 07:10:55酉鸡
日期:2014-04-02 12:24:51双子座
日期:2014-04-02 12:19:44天秤座
日期:2014-03-17 11:43:36亥猪
日期:2014-03-13 08:13:51未羊
日期:2014-03-11 12:42:03白羊座
日期:2013-11-20 10:15:18CU大牛徽章
日期:2013-04-17 11:48:45
7 [报告]
发表于 2010-08-23 09:34 |只看该作者
本帖最后由 rdcwayx 于 2010-08-23 09:37 编辑
awk -F, '{printf "%s,%d,%d,",$1,$2,"20100823,";for (i=3;i
99超人 发表于 2010-08-23 09:05


民工的这个好像搞的有些复杂了。
  1. awk -F , -v date=$(date +%Y%m%d) '{$2=$2 FS date ; gsub(/,$/,"")}1' OFS=, urfile
复制代码
如果不需要导入日期,可以更短:
  1. awk -F , '{$2=$2 ",20100823" ; gsub(/,$/,"")}1' OFS=, urfile
复制代码

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
8 [报告]
发表于 2010-08-23 09:42 |只看该作者
回复 1# jiaoli


    sed  's/,/,20080103,/;s/,$//'p urfile

求职 : 技术支持/维
论坛徽章:
0
9 [报告]
发表于 2010-08-23 09:48 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
10 [报告]
发表于 2010-08-23 09:51 |只看该作者
回复 8# greysky-zfj


    不知这个是否执行过
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP