我正在搜索正则表达式的任何匹配之前的行,并且 将输出放入数组变量中,因此我们可以使用正则表达式匹配行遍历 另一个数组。通过这种方式,我们知道 需要在每行的 末端将其打印出来时的内容。Bash Array; Sed AWK
<context name="Security" category="security" type="generic" optimizeSize="1">
<field name="BID_ASK_LASK_PRICE" type="double" id="0xFBCB" sequence="1" defaultValue="!null"/>
<field name="PX_OPEN_ALL_WITH_SWITCHOVER_RT" type="double" id="0x79F5" sequence="1" defaultValue="!null"/>
<field name="PX_CLOSE_ALL_WITH_SWITCHOVER_RT" type="double" id="0x79F6" sequence="1" defaultValue="!null"/>
<field name="PX_HIGH_ALL_WITH_SWITCHOVER_RT" type="double" id="0x79F7" sequence="1"
希望输出会出现字段名称| ID |上下文。在示例
CURRENT_SESSION_RT|0xFBCB|Security
PX_OPEN_ALL_WITH_SWITCHOVER_RT|0x79F5|Security
当前逻辑如下
#!/bin/bash
array=($(sed -n '/field name/{g;1!p;};h' $1))
array2=($(sed -n '/field name/p' $1))
for ((i=0;i<${#array[@]};++i)); do
ref=$(printf "${array2[1]}|" | sed 's/\"//g' | awk -F "=" '{print $2}')
name=$(printf "${array2[2]}|" | sed 's/[\"\>]//g' | awk -F "=" '{print $2}')
id=$(printf "${array[i]}\n" | sed 's/\"//g' | awk -F "=" '{print $2}')
printf "${ref}${name}${id}\n"
done
看起来是不迭代和附加适当作为输出只是重复以下
BID_ASK_LAST_PRICE|double|
BID_ASK_LAST_PRICE|double|"Security"
BID_ASK_LAST_PRICE|double|"security"
BID_ASK_LAST_PRICE|double|"generic"
BID_ASK_LAST_PRICE|double|"1">
BID_ASK_LAST_PRICE|double|
BID_ASK_LAST_PRICE|double|"Security"
BID_ASK_LAST_PRICE|double|"security"
BID_ASK_LAST_PRICE|double|"generic"
BID_ASK_LAST_PRICE|double|"1">
如何获得所需的输出输出?关于字段之间的关系的规范将是有用的 – nu11p01n73R 2014-10-30 16:36:21
我曾经运行下面的一个班轮,以获得字段名称和ID由“|”分隔。我现在正在寻找添加'上下文名称'grep'字段名称=“。* id =”'file.name | sed -e's /.* field name =“//'-e's /".* id =”/ | /'-e's /".*//'| grep -v“[ - ] 1 $” – 2014-10-30 16:39:38
@shelter我不确定你在暗示什么?我只是在寻求帮助。与大多数“卡住”或不是专家的人没有什么不同。你的建议是看看其他地方没有帮助的地方。 – 2014-10-30 16:56:56