如何使用bash

时间:2017-07-26 20:21:00

标签: bash

我有一个包含我的日志信息的文件:

Sat May 20 00:34:03 EST 2017 -- lane3a 4 0 -- lane3b 5 4 9 Total active sales: 4 Total bidders in sales: -- caster3a 0 -- caster3b 0 0 Total A/V 0 Estimated containers Sat May 20 00:35:03 EST 2017 -- lane3a 4 0 -- lane3b 5 4 9 Total active sales: 4 Total bidders in sales: -- caster3a 0 -- caster3b 0 0 Total A/V 0 Estimated containers Sat May 20 00:36:04 EST 2017 -- lane3a 4 0 -- lane3b 5 4 9 Total active sales: 4 Total bidders in sales: -- caster3a 0 -- caster3b 0 0 Total A/V 0 Estimated containers

我正在尝试将此日志数据拆分为行,因此它看起来像这样:

Sat May 20 00:34:03 EST 2017 -- lane3a 4 0 -- lane3b 5 4 9 Total active sales: 4 Total bidders in sales: -- caster3a 0 -- caster3b 0 0 Total A/V 0 Estimated containers 
Sat May 20 00:35:03 EST 2017 -- lane3a 4 0 -- lane3b 5 4 9 Total active sales: 4 Total bidders in sales: -- caster3a 0 -- caster3b 0 0 Total A/V 0 Estimated containers 
Sat May 20 00:36:04 EST 2017 -- lane3a 4 0 -- lane3b 5 4 9 Total active sales: 4 Total bidders in sales: -- caster3a 0 -- caster3b 0 0 Total A/V 0 Estimated containers

有什么想法吗?

3 个答案:

答案 0 :(得分:1)

使用sed

$ sed 's/containers */containers\n/g' file
Sat May 20 00:34:03 EST 2017 -- lane3a 4 0 -- lane3b 5 4 9 Total active sales: 4 Total bidders in sales: -- caster3a 0 -- caster3b 0 0 Total A/V 0 Estimated containers
Sat May 20 00:35:03 EST 2017 -- lane3a 4 0 -- lane3b 5 4 9 Total active sales: 4 Total bidders in sales: -- caster3a 0 -- caster3b 0 0 Total A/V 0 Estimated containers
Sat May 20 00:36:04 EST 2017 -- lane3a 4 0 -- lane3b 5 4 9 Total active sales: 4 Total bidders in sales: -- caster3a 0 -- caster3b 0 0 Total A/V 0 Estimated containers

或:

$ sed 's/\(containers\) */\1\n/g' file

答案 1 :(得分:0)

尝试:

perl -i.bkp -pe 's/containers/containers\n/' file.log

这假设单词containers应该位于每行的末尾

答案 2 :(得分:0)

您可以将整个文件读入Bash变量并使用参数扩展来替换python -V后的空格:

containers