How can I extract strings from one file to insert (modified) in a different file?
2
votes
5
answers
165
views
problem is the following:
I have an xml file with data and I am looking for a small part of the data to write it into a new file:
content has been shortened by request:
snippet if type=dhcp-client:
yes
Firewall
snippet if type=static
Firewall
192.168.0.2
255.255.255.0
192.168.0.1
192.168.0.1
ethernet1/4
0.0.0.0/0
the four relevant values are unique (or nonexistent) within the "system" tag
``
things like ip-address might appear again elsewhere outside of
``
but i am only checking for the ones inside system, if the type is not static dont appear, i set it to dhcp-client
this is what I need as a result in a file if the type is dhcp:
type=dhcp-client
this is what I need as a result in a file if the type was static:
type=static
ip-address=192.168.0.2
default-gateway=192.168.0.1
netmask=255.255.255.0
I am not sure how to accomplish this efficiently and integrated inside an existing **PHP** file (so either work with exec or better yet use php only).
I am also limited to tools that are installed by default on an ubuntu server system and would be unable to use other packages.
PS: this is actually the whole/complete use-case, I will not need to produce other output other than these two examples.
Thanks for any help or pointers :)
Asked by Questi
(55 rep)
Jan 14, 2020, 09:16 PM
Last activity: Jan 21, 2020, 01:47 AM
Last activity: Jan 21, 2020, 01:47 AM