Passer plusieurs variable dans awk enfin de mettre à jour un fichier XML
Résolu
GHISLINO
Messages postés
214
Date d'inscription
Statut
Membre
Dernière intervention
-
GHISLINO Messages postés 214 Date d'inscription Statut Membre Dernière intervention -
GHISLINO Messages postés 214 Date d'inscription Statut Membre Dernière intervention -
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
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
Merci d'avance pour les idées
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:
- Passer plusieurs variable dans awk enfin de mettre à jour un fichier XML
- Fichier bin - Guide
- Comment réduire la taille d'un fichier - Guide
- Comment ouvrir un fichier epub ? - Guide
- Mettre a jour chrome - Accueil - Applications & Logiciels
- Fichier rar - Guide
3 réponses
hello
essayer
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
$