[英]Please help fith edit text
please help me to edit, I need to take the names and s\n numbers.请帮我编辑,我需要取名字和 s\n 数字。 i try used sed,awk.
我尝试使用 sed,awk。 From this files
从这个文件
mq_operations_on_objects_theCommitShaToDownload_inventories: 'master'
mq_operationsOnObjects_mapComponentsOnSingleQm_inventories:
- { mnemoCode: 'TYY.B5NT', qmName: "{{ environment_name }}F01QM" }
mq_operationsOnObjects_sslCiph_inventories: "TLS_RSA_WITH_AES_256_CBC_SHA256"
mqOperationsOnObjects_dictOfComponents_inventories:
- { mnemoCode: 'BYU.KRGB', qmName: '', maxInstancesOfChannel: '20', remoteQmName: '', neighbouringQmName: '', neighbouringQmAddressAndPort: '', componentAddresses: '', matchingCertificatesValues: 'SERIALNUMBER=3E:00:00:6A:GH:8B:53:24:E1:4D:FG:E9:D3:00:00:00:09:6A:FC' }
- { mnemoCode: 'RTT.ECO', qmName: '', maxInstancesOfChannel: '20', remoteQmName: '', neighbouringQmName: '', neighbouringQmAddressAndPort: '', componentAddresses: '', matchingCertificatesValues: 'SERIALNUMBER=3E:00:00:61:D6:RT:03:FB:A0:D8:AC:6E:25:00:00:00:00:61:D6' }
- { mnemoCode: 'ASB.AML', qmName: '', maxInstancesOfChannel: '20', remoteQmName: '', neighbouringQmName: '', neighbouringQmAddressAndPort: '', componentAddresses: '', matchingCertificatesValues: 'SERIALNUMBER=3E:00:36:6A:F6:D4:4E:40:B4:1A:D9:DA:53:25:00:25:00:6A:F6' }
- { mnemoCode: 'CFT.RC', qmName: '', maxInstancesOfChannel: '50', remoteQmName: '', neighbouringQmName: '', neighbouringQmAddressAndPort: '', componentAddresses: '', matchingCertificatesValues: 'SERIALNUMBER=3E:00:00:67:1E:8C:77:ED:6D:F9:82:A2:6B:14:00:69:00:67:1E' }
- { mnemoCode: 'YTT.NHY', qmName: '', maxInstancesOfChannel: '20', remoteQmName: '', neighbouringQmName: '', neighbouringQmAddressAndPort: '', componentAddresses: '', matchingCertificatesValues: 'SERIALNUMBER=3E:00:00:67:D1:A1:F8:2B:5B:58:5D:BF:F9:25:00:00:00:67:D1' }
it needs to be like this它需要是这样的
BOS.KADR_SUV SERIALNUMBER=73:00:00:06:DF:F9:23:A1:CE:A1:71:4F:92:00:00:00:00:06:DF
BSS.ECO_SUV SERIALNUMBER=73:00:00:06:DF:F9:23:A1:CE:A1:71:4F:92:00:00:00:00:06:DF
CFT.AML_SUV SERIALNUMBER=73:00:00:06:DF:F9:23:A1:CE:A1:71:4F:92:00:00:00:00:06:DF
awk -F"^ *- { mnemoCode: '|', .*matchingCertificatesValues: '|' } *$" \
'$3 ~ /^SERIALNUMBER/ { printf "%-10s %s\n", $2, $3 }' tmp.file
It will sort out what you want as fields based on the regex inside -F"..."
and only output if field $3
starts with SERIALNUMBER
如果字段
$3
以SERIALNUMBER
开头,它将根据-F"..."
中的正则表达式和仅 output 将您想要的字段分类为字段
For good measure, a python version, making you able to parse the rows as python dictionary.为了更好地衡量,一个 python 版本,使您能够将行解析为 python 字典。
import json
import re
with open("tmp.file", "r") as f:
a = [row[4:] for row in f.read().splitlines()]
for row in a:
if "SERIALNUMBER" in row:
row = re.sub("'", '"', row)
row = re.sub(r' (\w+): ', '"\\1":', row)
row = json.loads(row)
print(row["mnemoCode"], row["matchingCertificatesValues"])
Start with the following to clean things up:从以下内容开始清理:
awk '{FS=","}/SERIAL/{print $1 $8;}'
and this is pretty close:这非常接近:
awk '{FS=","}/SERIAL/{print $1 $8;}' awk.txt | awk '{printf ("%s_SUV\t%s\n",$4, $6)}' | sed "s/'//g"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.