将大日志文件转换为csv

时间:2016-03-17 11:34:36

标签: csv unix command-line cygwin

我有一个带有以下结构的大文本文件(文件夹和文件):

\FOLDER1\
    3/21/2012 2:23:56 PM               2,178                   100               Good        myfile1.txt
    3/21/2012 1:24:25 PM         253,928,960                   100               Good        myfile2.txt
    3/21/2012 1:24:51 PM               6,430                   100               Good        myfile3.txt
    3/21/2012 10:28:03 AM            206,796                   100               Good        myfile4.txt

\FOLDER2\SUBFOLDER\
    3/21/2012 10:47:03 AM              1,300                   100               Good        bla.txt
    3/21/2012 10:42:56 AM             76,226                   100               Good        xyz.txt
    3/21/2012 1:25:08 PM       5,911,839,232                   100               Good        kkkkkk.txt
    3/21/2012 10:33:33 AM              1,202                   100               Good        mmmmm.txt
    3/21/2012 10:33:16 AM          3,412,079                   100               Good        mmmmmd.txt
    3/21/2012 10:32:21 AM                812                   100               Good        fg.txt
    3/21/2012 10:33:44 AM              1,206                   100               Good        sss.txt

我需要解析文件并提出格式化的CSV(分号为列)分隔符:

\FOLDER1\;3/21/2012 2:23:56 PM;2,178;100;Good;myfile1.txt
...
\FOLDER2\SUBFOLDER\;3/21/2012 10:47:03 AM;1,300;100;Good;bla.txt

谢谢!

1 个答案:

答案 0 :(得分:1)

sed -e '/^$/d' -e 's/  */;/g' filename

会将您的文件转换为:

\FOLDER1\
;3/21/2012;2:23:56;PM;2,178;100;Good;myfile1.txt
;3/21/2012;1:24:25;PM;253,928,960;100;Good;myfile2.txt
;3/21/2012;1:24:51;PM;6,430;100;Good;myfile3.txt
;3/21/2012;10:28:03;AM;206,796;100;Good;myfile4.txt
\FOLDER2\SUBFOLDER\
;3/21/2012;10:47:03;AM;1,300;100;Good;bla.txt
;3/21/2012;10:42:56;AM;76,226;100;Good;xyz.txt
;3/21/2012;1:25:08;PM;5,911,839,232;100;Good;kkkkkk.txt
;3/21/2012;10:33:33;AM;1,202;100;Good;mmmmm.txt
;3/21/2012;10:33:16;AM;3,412,079;100;Good;mmmmmd.txt
;3/21/2012;10:32:21;AM;812;100;Good;fg.txt
;3/21/2012;10:33:44;AM;1,206;100;Good;sss.txt

刚开始。

然后我认为你需要使用perl或awk来创建一个循环并连接该文件夹,直到它发生变化。

此致