Passer plusieurs variable dans awk enfin de mettre à jour un fichier XML

Résolu/Fermé
GHISLINO Messages postés 214 Date d'inscription lundi 25 juillet 2011 Statut Membre Dernière intervention 8 décembre 2023 - 22 nov. 2021 à 14:58
GHISLINO Messages postés 214 Date d'inscription lundi 25 juillet 2011 Statut Membre Dernière intervention 8 décembre 2023 - 29 nov. 2021 à 18:09
Bonjour,

J'ai des IP à mettre à jour dans un fichier XML , comment passer avec awk ou autre méthode afin de mettre à jour les IP

j'ai le fichier File c-dessous

 <managedObject class="com.nokia.srbts.tnl:SECPOL" distName="MRBTS-10758/TNLSVC-1/TNL-1/IPAPP-1/IPSECC-1/SECPOL-1" version="TNL19B_1907_001" operation="create">
<p name="ikePDN">MRBTS-10758/TNLSVC-1/TNL-1/IPAPP-1/IPSECC-1/IKEP-1</p>
<p name="ipSecAction">PROTECT</p>
<p name="ipSecPDN">MRBTS-10758/TNLSVC-1/TNL-1/IPAPP-1/IPSECC-1/IPSECP-1</p>
<p name="policyOrderNumber">10</p>
<p name="userLabel">4G</p>
<list name="trafficSelectorList">
<item>
<p name="localIpAddress">0.0.0.0</p>
<p name="localIpPort">-1</p>
<p name="localIpPrefixLength">32</p>
<p name="protocol">-1</p>
<p name="remoteIpAddress">0.0.0.0</p>
<p name="remoteIpPort">-1</p>
<p name="remoteIpPrefixLength">0</p>
</item>
</list>
</managedObject>
<managedObject class="com.nokia.srbts.tnl:SECPOL" distName="MRBTS-10758/TNLSVC-1/TNL-1/IPAPP-1/IPSECC-1/SECPOL-2" version="TNL19B_1907_001" operation="create">
<p name="ipSecAction">BYPASS</p>
<p name="policyOrderNumber">20</p>
<p name="userLabel">AOM</p>
<list name="trafficSelectorList">
<item>
<p name="localIpAddress">0.0.0.0</p>
<p name="localIpPort">-1</p>
<p name="localIpPrefixLength">32</p>
<p name="protocol">-1</p>
<p name="remoteIpAddress">0.0.0.0</p>
<p name="remoteIpPort">-1</p>
<p name="remoteIpPrefixLength">0</p>
</item>
</list>
</managedObject>
<managedObject class="com.nokia.srbts.tnl:SECPOL" distName="MRBTS-10758/TNLSVC-1/TNL-1/IPAPP-1/IPSECC-1/SECPOL-3" version="TNL19B_1907_001" operation="create">
<p name="ipSecAction">BYPASS</p>
<p name="policyOrderNumber">8</p>
<p name="userLabel">2G</p>
<list name="trafficSelectorList">
<item>
<p name="localIpAddress">0.0.0.0</p>
<p name="localIpPort">-1</p>
<p name="localIpPrefixLength">32</p>
<p name="protocol">-1</p>
<p name="remoteIpAddress">0.0.0.0</p>
<p name="remoteIpPort">-1</p>
<p name="remoteIpPrefixLength">0</p>
</item>
</list>
</managedObject>
<managedObject class="com.nokia.srbts.tnl:SECPOL" distName="MRBTS-10758/TNLSVC-1/TNL-1/IPAPP-1/IPSECC-1/SECPOL-4" version="TNL19B_1907_001" operation="create">
<p name="ipSecAction">BYPASS</p>
<p name="policyOrderNumber">30</p>
<p name="userLabel">3G</p>
<list name="trafficSelectorList">
<item>
<p name="localIpAddress">0.0.0.0</p>
<p name="localIpPort">-1</p>
<p name="localIpPrefixLength">32</p>
<p name="protocol">-1</p>
<p name="remoteIpAddress">0.0.0.0</p>
<p name="remoteIpPort">-1</p>
<p name="remoteIpPrefixLength">0</p>
</item>
</list>
</managedObject>



je dois mettre à jour "localIpAddress" des objet SECPOL1, SECPOL2, SECPOL3 et SECPOL4

avec les IP ci-dessous

IP1=1.1.1.1
IP2=2.2.2.2
IP3=3.3.3.3
IP4=4.4.4.4

Donc au final je doit obtenir le fichier Output_file ci-dessous


<managedObject class="com.nokia.srbts.tnl:SECPOL" distName="MRBTS-10758/TNLSVC-1/TNL-1/IPAPP-1/IPSECC-1/SECPOL-1" version="TNL19B_1907_001" operation="create">
<p name="ikePDN">MRBTS-10758/TNLSVC-1/TNL-1/IPAPP-1/IPSECC-1/IKEP-1</p>
<p name="ipSecAction">PROTECT</p>
<p name="ipSecPDN">MRBTS-10758/TNLSVC-1/TNL-1/IPAPP-1/IPSECC-1/IPSECP-1</p>
<p name="policyOrderNumber">10</p>
<p name="userLabel">4G</p>
<list name="trafficSelectorList">
<item>
<p name="localIpAddress">1.1.1.1</p>
<p name="localIpPort">-1</p>
<p name="localIpPrefixLength">32</p>
<p name="protocol">-1</p>
<p name="remoteIpAddress">0.0.0.0</p>
<p name="remoteIpPort">-1</p>
<p name="remoteIpPrefixLength">0</p>
</item>
</list>
</managedObject>
<managedObject class="com.nokia.srbts.tnl:SECPOL" distName="MRBTS-10758/TNLSVC-1/TNL-1/IPAPP-1/IPSECC-1/SECPOL-2" version="TNL19B_1907_001" operation="create">
<p name="ipSecAction">BYPASS</p>
<p name="policyOrderNumber">20</p>
<p name="userLabel">AOM</p>
<list name="trafficSelectorList">
<item>
<p name="localIpAddress">2.2.2.2</p>
<p name="localIpPort">-1</p>
<p name="localIpPrefixLength">32</p>
<p name="protocol">-1</p>
<p name="remoteIpAddress">0.0.0.0</p>
<p name="remoteIpPort">-1</p>
<p name="remoteIpPrefixLength">0</p>
</item>
</list>
</managedObject>
<managedObject class="com.nokia.srbts.tnl:SECPOL" distName="MRBTS-10758/TNLSVC-1/TNL-1/IPAPP-1/IPSECC-1/SECPOL-3" version="TNL19B_1907_001" operation="create">
<p name="ipSecAction">BYPASS</p>
<p name="policyOrderNumber">8</p>
<p name="userLabel">2G</p>
<list name="trafficSelectorList">
<item>
<p name="localIpAddress">3.3.3.3</p>
<p name="localIpPort">-1</p>
<p name="localIpPrefixLength">32</p>
<p name="protocol">-1</p>
<p name="remoteIpAddress">0.0.0.0</p>
<p name="remoteIpPort">-1</p>
<p name="remoteIpPrefixLength">0</p>
</item>
</list>
</managedObject>
<managedObject class="com.nokia.srbts.tnl:SECPOL" distName="MRBTS-10758/TNLSVC-1/TNL-1/IPAPP-1/IPSECC-1/SECPOL-4" version="TNL19B_1907_001" operation="create">
<p name="ipSecAction">BYPASS</p>
<p name="policyOrderNumber">30</p>
<p name="userLabel">3G</p>
<list name="trafficSelectorList">
<item>
<p name="localIpAddress">4.4.4.4</p>
<p name="localIpPort">-1</p>
<p name="localIpPrefixLength">32</p>
<p name="protocol">-1</p>
<p name="remoteIpAddress">0.0.0.0</p>
<p name="remoteIpPort">-1</p>
<p name="remoteIpPrefixLength">0</p>
</item>
</list>
</managedObject>


Merci d'avance pour les idées

Configuration: Windows / Chrome 96.0.4664.45
A voir également:

3 réponses

dubcek Messages postés 18744 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 4 septembre 2024 5 617
22 nov. 2021 à 18:10
hello
essayer
$ cat file1
SECPOL-1 IP1=1.1.1.1
SECPOL-2 IP2=2.2.2.2
SECPOL-3 IP3=3.3.3.3
SECPOL-4 IP4=4.4.4.4
$
$ cat f8.awk
NR==FNR {t[NR]=$1; t2[NR]=$3; next}
$0 ~ t[n] {x=1}
/localIpAddress/ && x {sub(">[0-9]+.[0-9]+.[0-9]+.[0-9]+<", ">" t2[n] "<"); x=0; n++ }
{print $0}
$
$ awk -F "[ =]" -v n=1 -f f8.awk file1 file > output_file
$
0
dubcek Messages postés 18744 Date d'inscription lundi 15 janvier 2007 Statut Contributeur Dernière intervention 4 septembre 2024 5 617
23 nov. 2021 à 11:05
et aussi
$ cat file1
1.1.1.1
2.2.2.2
3.3.3.3
4.4.4.4
$
$ cat f9.awk
NR==FNR {t[NR]=$1; next}
/SECPOL-[0-9]+/{n=gensub("(^.*SECPOL-)([0-9]+)(.*$)", "\\2", 1, $0)}
/localIpAddress/ && n {sub(">[0-9]+.[0-9]+.[0-9]+.[0-9]+<", ">" t[n] "<"); n=0 }
{print $0}
$
$ awk -f f9.awk file1 file > output_file
$
0
GHISLINO Messages postés 214 Date d'inscription lundi 25 juillet 2011 Statut Membre Dernière intervention 8 décembre 2023
29 nov. 2021 à 18:09
hello dubcek,

C est parfait , Merci Bcp ,
0