Tag Info

New answers tagged

1

Perl has a nifty "paragraph mode" (-00) where records ("lines") are separated by a blank line instead of a single \n character. Using this, you can very easily extract the relevant records. So, first make sure that there is a blank line before each <block>, and then use paragraph mode to find what you're searching for: $ sed ...


-3

echo "Hello" java -Xms512m -Xmx3048m -jar xml2csv-conv.jar -k attr_list source_file.xml destination_file.nnmpa1.csv


0

At risk of sounding like a broken record - XML is a data structure, and there's a variety of things that can be done to this data structure that are valid as far as the XML spec goes, but that completely break it as far as regular expressions go. Things like line formatting, indendation, wrapping of tags etc. So I strongly urge anyone - when processing XML ...


2

Provided your XML in data.xml as: $ cat data.xml <?xml version="1.0" encoding="UTF-8"?> <root> <part name="D_wheel1" seqNumber="1"> <yrot min="0.000000" max="0.000000" cur="0.000000" /> </part> <part name="D_wheel2" seqNumber="1"> <yrot min="0.000000" max="0.000000" ...


2

There is a massive problem with trying to parse XML with 'standard' unix tools. XML is a data structure, and it supports a variety of layouts that are semantically identically, but don't have the same line and indentation. This means it's really a bad idea to parse as line/regex based, because you'll be creating some fundamentally brittle code. Someone ...


0

Using awk. Note that this assumes a very simple file structure like the one you show. I cannot guarantee that it will work on arbitrary XLM files. In fact, I can flat out guarantee it won't. awk '{if(/<\/part>/){p=0}if($1~/<part/ && $2~/wheel/){p=1} if(p==1 && /<yrot/){ print "<yrot min=\"INF\" max=\"INF\"/>" ...


2

Using python's ElementTree standard library: #! /usr/bin/env python import sys import xml.etree.ElementTree as ET def do_one(file_name): tree = ET.parse(file_name) for part in tree.findall("part"): if not 'wheel' in part.attrib['name']: continue for yrot in part.findall('yrot'): names = [] for x ...



Top 50 recent answers are included