我试图通过使用awk将此文件操作为我想要的格式。 这是输入和所需的输出。请帮帮....
输入文件
================================================================================================================= 0 Managed=1 ================================================================================================================= ManagedId 1 application t[0] = faultTolStates s[2] = Managed=1,Equipment=1 helChRe Struct{3} >>> 1.helCheResCode = 99 (INITIAL_VALUE) >>> 2.message = >>> 3.startTime = helCheSched t[0] = loglName QWERT01 mimInfo Struct{3} >>> 1.mimName = QWERT_NO_MODEL >>> 2.mimVersion = 1.2564 >>> 3.mimRelease = productName XYZ1234 productNumber productRevision productType Node site QWERT01 userLabel QWERT01 ================================================================================================================= 1 Managed=2 ================================================================================================================= etc..... etc.... etc.... etc....
所需的输出文件
Managed=1 ManagedId 1 Managed=1 application t[0] = Managed=1 faultTolStates s[2] = Managed=1,Equipment=1 Managed=1 helChRe Struct{3} Managed=1 helCheResCode 99 (INITIAL_VALUE) Managed=1 message Managed=1 startTime Managed=1 helCheSched t[0] = Managed=1 logName QWERT01 Managed=1 mimInfo Struct{3} Managed=1 mimName QWERT_NO_MODEL Managed=1 mimVersion 1.2564 Managed=1 mimRelease Managed=1 productName XYZ1234 Managed=1 productNumber Managed=1 productRevision Managed=1 productType Node Managed=1 site QWERT01 Managed=1 userLabel QWERT01 Managed=2 ETC ............. Managed=2 ETC............. Managed=2 ETC............. Managed=2 ETC............. Managed=2 ETC............. Managed=2 ETC.............
答案 0 :(得分:-1)
这可能没有完全考虑到数据的所有细节,但对于示例输入,至少它似乎给出了所需的输出。在最坏的情况下,它应该是一个很好的起点:
$ awk '$1 ~ /^[0-9]/ && $2 ~ /Managed=[0-9]/ { prefix=$2; next } !($1 ~ /^========/) { print prefix, $0 }' managed.txt
Managed=1 ManagedId 1
Managed=1 application t[0] =
Managed=1 faultTolStates s[2] = Managed=1,Equipment=1
Managed=1 helChRe Struct{3}
Managed=1 >>> 1.helCheResCode = 99 (INITIAL_VALUE)
Managed=1 >>> 2.message =
Managed=1 >>> 3.startTime =
Managed=1 helCheSched t[0] =
Managed=1 loglName QWERT01
Managed=1 mimInfo Struct{3}
Managed=1 >>> 1.mimName = QWERT_NO_MODEL
Managed=1 >>> 2.mimVersion = 1.2564
Managed=1 >>> 3.mimRelease =
Managed=1 productName XYZ1234
Managed=1 productNumber
Managed=1 productRevision
Managed=1 productType Node
Managed=1 site QWERT01
Managed=1 userLabel QWERT01
Managed=2 etc.....
Managed=2 etc....
Managed=2 etc....
Managed=2 etc....