Linux日志文件通过脚本解析语法

时间:2018-06-01 04:30:43

标签: linux bash

我输出的一个命令是:

 15 |TotalCount Hour=23 Date=2018-05-29 Result-Code=5001 AVPcode=1263
 10 |TotalCount Hour=22 Date=2018-05-29 Result-Code=5001 AVPcode=1263
 21 |TotalCount Hour=21 Date=2018-05-29 Result-Code=5001 AVPcode=1263
 20 |TotalCount Hour=20 Date=2018-05-29 Result-Code=5001 AVPcode=1263
 20 |TotalCount Hour=19 Date=2018-05-29 Result-Code=5001 AVPcode=1263
 22 |TotalCount Hour=18 Date=2018-05-29 Result-Code=5001 AVPcode=1263
 47 |TotalCount Hour=17 Date=2018-05-29 Result-Code=5001 AVPcode=1263
 39 |TotalCount Hour=16 Date=2018-05-29 Result-Code=5001 AVPcode=1263
 44 |TotalCount Hour=15 Date=2018-05-30 Result-Code=5001 AVPcode=1263
 38 |TotalCount Hour=14 Date=2018-05-30 Result-Code=5001 AVPcode=1263

当我在脚本中使用此命令并将其输出到X时,它变为:

 15 |TotalCount Hour=23 Date=2018-05-29 Result-Code=5001 AVPcode=1263 10 |TotalCount Hour=22 Date=2018-05-29 Result-Code=5001 AVPcode=1263 21 |TotalCount Hour=21 Date=2018-05-29 Result-Code=5001 AVPcode=1263 20 |TotalCount Hour=20 Date=2018-05-29 Result-Code=5001 AVPcode=1263 20 |TotalCount Hour=19 Date=2018-05-29 Result-Code=5001 AVPcode=1263 22 |TotalCount Hour=18 Date=2018-05-29 Result-Code=5001 AVPcode=1263 47 |TotalCount Hour=17 Date=2018-05-29 Result-Code=5001 AVPcode=1263 39 |TotalCount Hour=16 Date=2018-05-29 Result-Code=5001 AVPcode=1263 44 |TotalCount Hour=15 Date=2018-05-30 Result-Code=5001 AVPcode=1263 38 |TotalCount Hour=14 Date=2018-05-30 Result-Code=5001 AVPcode=1263 28 |TotalCount Hour=13 Date=2018-05-30 Result-Code=5001 AVPcode=1263 30 |TotalCount Hour=12 Date=2018-05-30 Result-Code=5001 AVPcode=1263 36 |TotalCount Hour=11 Date=2018-05-30 Result-Code=5001 AVPcode=1263 50 |TotalCount Hour=10 Date=2018-05-30 Result-Code=5001 AVPcode=1263 38 |TotalCount Hour=09 Date=2018-05-30 Result-Code=5001 AVPcode=1263 20 |TotalCount Hour=08 Date=2018-05-30 Result-Code=5001 AVPcode=1263 6 |TotalCount Hour=07 Date=2018-05-30 Result-Code=5001 AVPcode=1263 2 |TotalCount Hour=00 Date=2018-05-30 Result-Code=5001 AVPcode=1263

如何在X

中获得相同的语法

2 个答案:

答案 0 :(得分:1)

您可以简单地使用双引号"$x"echo来获取变量值中的行。请参阅这些示例。

x="here is the first line.
Here is the second line."

现在我们打印echo $x

here is the first line. Here is the second line.

现在,当我们打印echo "$x"时,输出将使用新行,如下所示。

here is the first line.
Here is the second line.

答案 1 :(得分:0)

您可以将\ n添加到行尾。第一个斜杠是转义第二个斜杠,\ n是换行符。

现在,当你打印出变量时,它将打印出你喜欢的新行。