这个我这个月没来怎么办啊

ChinaUnix.net's Archiver
帮忙看看这个问题怎么办啊
wxusheng
发表于 2010-09-29 09:23
帮忙看看这个问题怎么办啊
现在有各TEXT,需要括号内的时间分裂出来怎么办啊,如下表
aa time hh kk ll
262310 1284943062 (2010-09-19 12:37:42) 1284943061 (2010-09-19 12:37:41) 946728000 (2000-01-01 00:00:00) 1198194710 (cc)
264735 1284942984 (2010-09-19 12:36:24) 1284942965 (2010-09-19 12:36:05) 1284942967 (2010-09-19 12:36:07) 0 ( )
267177 1284943004 (2010-09-19 12:36:44) 1284942990 (2010-09-19 12:36:30) 1284942991 (2010-09-19 12:36:31) 1198194710 (aa)
需要把上面这个表变成下面这各表,怎么实现啊 这只是其中几列,还有好多这种列都要变呢
aa time hh kk ll
262310 2010-9-19 12:37 2010-9-19 12:37 2000-1-1 0:00 1198194710
264735 2010-9-19 12:36 2010-9-19 12:36 2010-9-19 12:36 0
267177 2010-9-19 12:36 2010-9-19 12:36 2010-9-19 12:36 1198194710
longbow0
发表于 2010-09-29 09:45
#!/usr/bin/perl
use strict;
use warning while (DATA) { next if /^\s*$/; print if /^\D/; if (/^(\d+).+?\(([\d\-]+)\s(\d{1,2}:\d{1,2}).+?\(([\d\-]+)\s(\d{1,2}:\d{1,2}).+?\(([\d\-]+)\s(\d{1,2}:\d{1,2}):\d+\)\s+(\d+)/) { rint join(\t, ($1, $2, $3, $4, $5, $6, $7, $8)), \ quot }
exit 0;
__DATA__
aa time hh kk ll
262310 1284943062 (2010-09-19 12:37:42) 1284943061 (2010-09-19 12:37:41) 946728000 (2000-01-01 00:00:00) 1198194710 (cc)
264735 1284942984 (2010-09-19 12:36:24) 1284942965 (2010-09-19 12:36:05) 1284942967 (2010-09-19 12:36:07) 0 ( )
267177 1284943004 (2010-09-19 12:36:44) 1284942990 (2010-09-19 12:36:30) 1284942991 (2010-09-19 12:36:31) 1198194710 (aa)
[/code]
wxusheng
发表于 2010-09-29 09:47
楼上多谢,要是处理文本文件怎么写啊有很多行
珞水的大叔
发表于 2010-09-29 10:05
[i=s] 本帖最后由 珞水的大叔 于 2010-09-29 10:29 编辑 [/i]
perl -pe 's/\s\d+\s\((\d[^)]+):\d\d\)/ $1/g /\s\([^)]*\)$//g' 文件名
试试这个
发表于 2010-09-29 10:11
[b]回复 [url=http:// .chinaunix.net/redirect.php?goto=findpost&am id=12927027&am tid=1793384]4#[/url] [i]珞水的大叔[/i] [/b] 应该用pe,不是ne
珞水的大叔
发表于 2010-09-29 10:14
[b]回复 [url=http:// .chinaunix.net/redirect.php?goto=findpost&am id=12927068&am tid=1793384]5#[/url] [i]99超人[/i] [/b] 就是让他看一下先,呵呵,免得改了源文件 重定向一下就可以了:lol
发表于 2010-09-29 10:18
[b]回复 [url=http:// .chinaunix.net/redirect.php?goto=findpost&am id=12927105&am tid=1793384]6#[/url] [i]珞水的大叔[/i] [/b] 用n啥都看不到
用i参数才会直接修改文件
珞水的大叔
发表于 2010-09-29 10:29
[b]回复 [url=http:// .chinaunix.net/redirect.php?goto=findpost&am id=12927151&am tid=1793384]7#[/url] [i]99超人[/i] [/b]
确实……
我忘了以前ne的时候都是自己写的print
我改一下
多谢超人啦
wxusheng
发表于 2010-09-29 16:41
谢谢楼上,会报错啊
D:\CDT_Parse后文件> erl -pe 's/\s\d+\s\((\d[^)]+):\d\d\)/ $1/g /\s\([^)]*\)$//g
' CDT_重庆1X呼叫_20100924_150124.dat
Can't find string terminator ' anywhere before EOF at -e line 1.
D:\CDT_Parse后文件> erl -pe s/\s\d+\s\((\d[^)]+):\d\d\)/ $1/g /\s\([^)]*\)$//g
CDT_重庆1X呼叫_20100924_150124.dat
Su titution replacement not terminated at -e line 1.
D:\CDT_Parse后文件> erl -ne s/\s\d+\s\((\d[^)]+):\d\d\)/ $1/g /\s\([^)]*\)$//g
CDT_重庆1X呼叫_20100924_150124.dat
Su titution replacement not terminated at -e line 1.
发表于 2010-09-29 16:54
[b]回复 [url=http:// .chinaunix.net/redirect.php?goto=findpost&am id=12926665&am tid=1793384]1#[/url] [i]wxusheng[/i] [/b]
If the data of row is seperated with tab \t, the easy way is to use lit() method.
my ($aa, $time, $hh, $kk, $ll) = lit \t, $line, 5;
# then using regex to match time, hh, kk and ll
wxusheng
发表于 2010-09-29 16:55
这是原始文件,需要转换,把时间上的括号去掉2010-09-19 12:36:44 时要成这种格式
发表于 2010-09-29 17:15
[b]回复 [url=http:// .chinaunix.net/redirect.php?goto=findpost&am id=12930761&am tid=1793384]11#[/url] [i]wxusheng[/i] [/b] [oracle@imeg02 zgw]$ perl -pe 's/\d+\s+\((.*?:\d+)\)/\1/g /\(.*?\)$//g' file
aa time hh kk ll
262310 2010-09-19 12:37:42 2010-09-19 12:37:41 2000-01-01 00:00:00 1198194710
264735 2010-09-19 12:36:24 2010-09-19 12:36:05 2010-09-19 12:36:07 0
267177 2010-09-19 12:36:44 2010-09-19 12:36:30 2010-09-19 12:36:31 1198194710
在Windows下运行,把单引号改成双引号
wxusheng
发表于 2010-09-29 17:26
需要把文件中的时间变为2010-09-19 12:37:42 这种格式,附件是文件多谢
magnet2008
发表于 2010-09-29 17:38
#利用正则表达式解决
while ( my $line = DATA ) { chomp $line; $line =~/ (\d+) #匹配开头数字 [^(]+ #括号左边所有的 \((.*?):\d+\) #利用?进行最短匹配 [^(]+\((.*?):\d+\) #三个相同的匹配 [^(]+\((.*?):\d+\) \s+(\d+) .* #剩余的结尾 /x; print $1\t$2\t$3\t$4\t$5\ quot }
__DATA__
262310 1284943062 (2010-09-19 12:37:42) 1284943061 (2010-09-19 12:37:41) 946728000 (2000-01-01 00:00:00) 1198194710 (cc)
264735 1284942984 (2010-09-19 12:36:24) 1284942965 (2010-09-19 12:36:05) 1284942967 (2010-09-19 12:36:07) 0 ( )
267177 1284943004 (2010-09-19 12:36:44) 1284942990 (2010-09-19 12:36:30) 1284942991 (2010-09-19 12:36:31) 1198194710 (aa)
262310 2010-09-19 12:37 2010-09-19 12:37 2000-01-01 00:00 1198194710
264735 2010-09-19 12:36 2010-09-19 12:36 2010-09-19 12:36 0
267177 2010-09-19 12:36 2010-09-19 12:36 2010-09-19 12:36 1198194710
magnet2008
发表于 2010-09-29 17:39
#利用正则表达式解决
while ( my $line = DATA ) { chomp $line; $line =~/ (\d+) #匹配开头数字 [^(]+ #括号左边所有的 \((.*?):\d+\) #利用?进行最短匹配 [^(]+\((.*?):\d+\) #三个相同的匹配 [^(]+\((.*?):\d+\) \s+(\d+) .* #剩余的结尾 /x; rint $1\t$2\t$3\t$4\t$5\ quot }
__DATA__
262310 1284943062 (2010-09-19 12:37:42) 1284943061 (2010-09-19 12:37:41) 946728000 (2000-01-01 00:00:00) 1198194710 (cc)
264735 1284942984 (2010-09-19 12:36:24) 1284942965 (2010-09-19 12:36:05) 1284942967 (2010-09-19 12:36:07) 0 ( )
267177 1284943004 (2010-09-19 12:36:44) 1284942990 (2010-09-19 12:36:30) 1284942991 (2010-09-19 12:36:31) 1198194710 (aa)
262310 2010-09-19 12:37 2010-09-19 12:37 2000-01-01 00:00 1198194710
264735 2010-09-19 12:36 2010-09-19 12:36 2010-09-19 12:36 0
267177 2010-09-19 12:36 2010-09-19 12:36 2010-09-19 12:36 1198194710
珞水的大叔
发表于 2010-09-29 20:05
[b]回复 [url=http:// .chinaunix.net/redirect.php?goto=findpost&am id=12930629&am tid=1793384]9#[/url] [i]wxusheng[/i] [/b] 啊,你是在windows上啊 把单引号换成双引号试试
wxusheng
发表于 2010-10-03 22:09
时间前面是空格不是制表符,需要在时间前面是制表符,怎么做楼上的想想办法
珞水的大叔
发表于 2010-10-04 10:16
[b]回复 [url=http:// .chinaunix.net/redirect.php?goto=findpost&am id=12943593&am tid=1793384]17#[/url] [i]wxusheng[/i] [/b] 你是说,原来的文本时间前面是制表符,还是想要替换后的时间前面是制表符啊
珞水的大叔
发表于 2010-10-04 11:17
[b]回复 [url=http:// .chinaunix.net/redirect.php?goto=findpost&am id=12943593&am tid=1793384]17#[/url] [i]wxusheng[/i] [/b] perl -pe 's/\s\d+\s\((\d[^)]+):\d\d\)/\t$1/g /\s\([^)]*\)$//g' 文件名
这样就OK,
如果是windows机器把单引号换成双引号即可
wxusheng
发表于 2010-10-04 13:46
太谢谢楼上了,可以了,多谢多谢,不过我先前写错了,转换后的时间是需要秒的,麻烦大侠看看怎么改一下
查看完整版本:
Powered by
7.2 2001-2009已解决问题
回答采纳率:46.2%
2011-07-12 22:00
Copyright 1998 – 2011 Tencent. All Rights Reserved.
在上方输入您感兴趣的知识,点击搜索***后,下方将出现您感兴趣的问题列表。
进入任一您感兴趣的问题查看,点选其满意***处的4个评价按钮之一,即可完成对该满意***的评价。已解决问题
回答采纳率:35.7%
2008-11-29 15:07
的感言:
Copyright 1998 – 2011 Tencent. All Rights Reserved.
在上方输入您感兴趣的知识,点击搜索***后,下方将出现您感兴趣的问题列表。
进入任一您感兴趣的问题查看,点选其满意***处的4个评价按钮之一,即可完成对该满意***的评价。

参考资料

 

随机推荐