New answers tagged

2

With vim there is more than one way to do it: 1 - Visual selection A more detailed explanation of Mikhail Krutov comment about visual selection: /Directory to find the first match Shift + v (visual mode) /Directory> to select all(select until find Directory> You can also hit } twice to select 2 paragraphs instead of using the search. ...


1

With perl, it's as easy as: perl -pe 'if ((/<Directory/ && !$done) ... /<\/Directory/) { $done = true; s/^/#/; }' < config_file The trick is the three-dots operators (the two-dots works also as long as <Directory> and </Directory> are not in the same line). /<Directory/ ... /<\/Directory/ matches all line between these ...


0

If you want to add an LF after every closing tag, you could use sed: sed -e 's:</[^>]*>:&\n:g' inputfile.xml Use \r or \r\n if you really want a CR or CRLF instead of just an LF (aka "newline"). Optionally use sed's -i or --in-place option to cause the actual input file(s) to be changed, rather than just output to stdout. sed -i -e ...


0

unix2dos <file> the file char method is very tricky when it comes to read config in both, UX (LF) or Windows (CRLF), even on Mac (CR) http://www.linuxcommand.org/man_pages/dos2unix1.html dos2unix to convert CRLF > LF http://linuxcommand.org/man_pages/unix2dos1.html unix2dos to convert LF > CRLF Notepad++ allows your to search and replace those /n ...


2

You can enumerate the directory contents as follows: my @files = <*.xml>; # or: my @files = </your/path/to/*.xml>; foreach my $file (@files) { $twig->parsefile($file); }


1

First some comments/questions to get you thinking in a different way: (in other words, this started as a comment but became an actual answer somewhere along the way) Why are you even trying to extract the devicename element when you already know it - it's what you used to fetch the XML (with name=devicename in the URL)? Even if you didn't already have it, ...


1

Use s:::g rather than s///g in your example not to escape '/' symbol: sed -i 's:</\?sellingStatus>::g' file.xml


3

It is not always a good idea to sed xml file, however sed -i -e 's:</sellingStatus>::g' -e 's:<sellingStatus>::g' file.xml substitute command in sed can be delimited by arbitrary char. (here : )


0

As you have not specified whether you want to replace the string globally or not, I am assuming it to replace for specific line, so command would be, sed -i '6s+ currencyId="GBP"++' filename.xml It's better to backup the file before editing, so to be on safer side I would use, sed -i.bak '6s+ currencyId="GBP"++' filename.xml


2

sed -i 's/ currencyId="GBP"//' file.xml - This works for me. Add a g at the end of the sed command if you want to replace all instances.


0

This is not possible. One solution I created was to create my own "root tag" called <volumeCollection> and have my own XML scanner find all of the <volume> tags and call virsh vol-create for each of them found. It's a wrapper solution, but accomplished what I needed.



Top 50 recent answers are included