-2

I have a file with these code:

    ...
<JOB id="5828" APPLICATION="applic" NAME="dsfsdfs" JOB="34324" DOCdB="EXW.ALLFUNBS.DOC" DOCdd="U4CMF1CA" INTERVAL="00001M" MEMLIB="EXW.ALLFUNBS.JCL" CMDLINE="script.sh sdfsf" CONFIRM="0" RETRO="0" MAXWAIT="98" MAXDAYS="0" MAXRUNS="0" TIMEFROM="0100" DAYS="33,22" JAN="1" FEB="0" sdfdsf="N" 324324="N" VERSION_OPCODE="N" 32423424="Y" VERSION_SERIAL="2" sdfdsf="DESKTOPdf-d" dsfdsfs="0" 23453="C" 435435435="adfdsf">
...

I'm trying to get all lines that have the filed DAYS

DAYS="33,22"

I'm trying with sed and grep but don't works. Anyone could help to get the info? Thanks and sorry for my English

defekas17
  • 155
  • 1
  • 9

1 Answers1

1

Don't use sed nor regex to parse XML you cannot, must not parse any structured text like XML/HTML with tools designed to process raw text lines. If you need to process XML/HTML, use an XML/HTML parser. A great majority of languages have built-in support for parsing XML and there are dedicated tools like XMLStarlet if you need a quick shot from a command line shell. Never accept a job if you don't have access to proper tools.

With xidel:

$ xidel -e '//JOB/@DAYS' file.xml
33,22

With xmlstarlet:

$ xmlstarlet format -R file.xml | sponge file.xml
$ xmlstarlet sel -t -v '//JOB/@DAYS' file.xml
33,22
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223