Parse a CSV file and insert its content as new lines before the last matching pattern using sed or awk or any unix utils -
i parse csv file , insert content new lines before last matching pattern (matching pattern ) in file.
csv file contents
10.200.1.20,255.255.255.0 10.200.1.30,255.255.255.0
second file insertion required:
<!-- example ip list <iplist> </iplist> example end --> <iplist> <ip node_id="100.10.10.10" netmask="255.255.255.0"/> <ip node_id="100.10.10.10" netmask="255.255.255.0"/> </iplist>
please me in how achieve this
to handle xml, use proper xml handling tools. example, task can accomplished following xsh script:
open input.xml ; perl { open $fh, '<', 'file.csv' or die $! } ; while { $line = <$fh> } { $line = normalize-space($line) ; # remove final newline. $ip := insert element ip append /iplist ; set $ip/@node_id substring-before($line, ",") ; set $ip/@netmask substring-after($line, ",") ; insert text {"\n"} after $ip ; } save :b ;
Comments
Post a Comment