在 bash 或 C-shell 中解析和格式化数据

问题描述 投票:0回答:0

我有来自命令的以下格式的输入数据,我需要使用 foreach 循环或 awk 或任何有效的技术来解析它以获得所需的输出,如下所示。

输入数据:

General Information
  Job = Job1
  Workstation Folder = /test/
  Workstation = xyz-test
  Monitored = No
  Requires Confirmation = No
  Interactive = No
  Critical = No
Runtime Information
  Status = Successful
  Internal Status = SUCC
  Not Satisfied Dependencies = 0
  Rerun Options =
  Rerun on the same workstation = No
  Information =
  Promoted = No
  Return Code = 0
  Return Code Mapping Expression =
Time Information
  Actual Start = 04/30/2023 00:00:05 TZ EDT
  Earliest Start = 04/30/2023 00:00:00 TZ EDT
  Latest Start = 04/30/2023 23:59:00 TZ EDT
  Latest Start Action = Suppress
  Maximum Duration =
  Maximum Duration Action =
  Minimum Duration =
  Minimum Duration Action =
  Critical Latest Start =
Recovery Information
  Action = Stop
  Message =
  Job Definition =
  Workstation Folder =
  Workstation =
Extra Run Information
  -
General Information
  Job = Job2
  Workstation Folder = /test/
  Workstation = xyz-test
  Monitored = No
  Requires Confirmation = No
  Interactive = No
  Critical = No
Runtime Information
  Status = Running
  Internal Status = EXEC
  Not Satisfied Dependencies = 0
  Rerun Options = Every run
  Rerun on the same workstation = No
  Information = Every
  Promoted = No
  Return Code =
  Return Code Mapping Expression =
Time Information
  Actual Start = 04/30/2023 19:17:12 TZ EDT
  Earliest Start = 04/30/2023 19:15:00 TZ EDT
  Latest Start = 04/30/2023 23:59:00 TZ EDT
  Latest Start Action = Suppress
  Maximum Duration =
  Maximum Duration Action =
  Minimum Duration =
  Minimum Duration Action =
  Critical Latest Start =
Recovery Information
  Action = Stop
  Message =
  Job Definition =
  Workstation Folder =
  Workstation =
  Extra Run Information
  -

可以通过解析输入数据和使用输入字段来填充输出,如下所示。

例如。 $Job(来自一般信息).$Actual Start(来自时间信息).$Actual Start(来自时间信息).$Internal Status(来自运行时信息)

预期产出:

Job1.04/30/2023.00:00:05.SUCC
Job2.04/30/2023.19:17:12.EXEC
bash for-loop awk foreach csh
© www.soinside.com 2019 - 2024. All rights reserved.