deleting lines from many xml documents

Discussion in 'XML' started by Nora, Aug 16, 2004.

  1. Nora

    Nora Guest

    Hi,

    I have about 200 xml files which contain one line, that I want to delete.
    This line is always the last line of the file and it always begins with
    "<?Pub"
    Transformations don't work as due to this line the document ist not valid
    and saxon won't perform the transformation.

    Has anyone an idea how I can get rid of this last line in all documents
    without having to open all documents and deleting manually?

    Thanks in advance for your help!
    Nora
    Nora, Aug 16, 2004
    #1
    1. Advertising

  2. Nora wrote:


    > I have about 200 xml files which contain one line, that I want to delete.
    > This line is always the last line of the file and it always begins with
    > "<?Pub"
    > Transformations don't work as due to this line the document ist not valid
    > and saxon won't perform the transformation.
    >
    > Has anyone an idea how I can get rid of this last line in all documents
    > without having to open all documents and deleting manually?


    If it is not well-formed then it is not XML and judging from your
    comments it sounds as if it is not XML so any XML parser won't help. But
    reading in text files line by line and writing some of the lines back is
    a task that can be solved by many programming languages.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Aug 16, 2004
    #2
    1. Advertising

  3. Nora

    Boris Stumm Guest

    Nora wrote:
    > I have about 200 xml files which contain one line, that I want to delete.
    > This line is always the last line of the file and it always begins with
    > "<?Pub"
    > Transformations don't work as due to this line the document ist not valid
    > and saxon won't perform the transformation.


    In Unix/Linux I'd do it this way:

    mkdir new
    for i in *.xml ; do
    grep -v "^<\?Pub" $i > new/$i
    done
    mv new/* .
    rmdir new

    Not tested, it can well be that the syntax is somewhat wrong. But
    you get the idea.

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.2 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

    iD8DBQFBIL2lszjGeKyO8GsRAhQdAJwMOpetLc5orjc57nW5a3D3gg3MjACfRvRk
    HWc4pIOM7pBQ2GvB7PVnfEg=
    =Y5L4
    -----END PGP SIGNATURE-----
    Boris Stumm, Aug 16, 2004
    #3
  4. Grep for windows (use version 2.2)

    http://www.wingrep.com/download.html


    --
    ---------------------------------
    Trevor Lowing
    Satellite Beach, Fl


    ---------------------------------
    Need help with:
    Access?
    http://www.mvps.org/access/
    Outlook?
    http://www.slipstick.com/
    Visio?
    http://www.mvps.org/visio/
    HTML/CSS?
    http://www.NCDesign.org
    Scripting(VBScript/JScript/WSH/XML)?
    http://www.DevGuru.com
    http://cwashington.netreach.net/
    http://developer.irt.org/script/script.htm
    ---------------------------------
    Trevor Lowing, Aug 16, 2004
    #4
  5. Nora

    Nora Guest

    Trevor,

    I downloaded the Grep for windows. But I don't quite see, how it should help
    me with my problem.
    I want to replace the last line of each document. These lines are not
    completely similar in their content. But all of them start the same way. (so
    simple find and replace won't help)
    Did you understand me that way? And if yes, how should the Grep help me?

    Thanks, Nora



    "Trevor Lowing" <> schrieb im Newsbeitrag
    news:...
    > Grep for windows (use version 2.2)
    >
    > http://www.wingrep.com/download.html
    >
    >
    > --
    > ---------------------------------
    > Trevor Lowing
    > Satellite Beach, Fl
    >
    >
    > ---------------------------------
    > Need help with:
    > Access?
    > http://www.mvps.org/access/
    > Outlook?
    > http://www.slipstick.com/
    > Visio?
    > http://www.mvps.org/visio/
    > HTML/CSS?
    > http://www.NCDesign.org
    > Scripting(VBScript/JScript/WSH/XML)?
    > http://www.DevGuru.com
    > http://cwashington.netreach.net/
    > http://developer.irt.org/script/script.htm
    > ---------------------------------
    Nora, Aug 17, 2004
    #5
  6. Nora wrote:

    > I downloaded the Grep for windows. But I don't quite see, how it should help
    > me with my problem.
    > I want to replace the last line of each document. These lines are not
    > completely similar in their content. But all of them start the same way. (so
    > simple find and replace won't help)
    > Did you understand me that way? And if yes, how should the Grep help me?
    >


    As far as I know grep is a search tool only - except the version
    mentioned (Wingrep 2.2 or higher) has some extra features, e.g.
    if it supplies an option to delete the line matching a search ex-
    pression it would solve your problem:

    The regular expression ^<\?Pub identifies all lines beginning
    with <?Pub (^ is for beginning of line, \ is the escape character
    becaus ? has a special meaning).

    If you have access to *nix or cygwin you could apply the following
    command to each xml-file:

    cat xmlfile.xml | sed '/^<\?Pub/d' > xmlfile-new.xml

    This will delete all lines starting with <?Pub - Wingrep 2.2
    might have similar features.

    HTH,
    Gerald
    Gerald Aichholzer, Aug 17, 2004
    #6
  7. Nora

    William Park Guest

    Nora <> wrote:
    > Hi,
    >
    > I have about 200 xml files which contain one line, that I want to delete.
    > This line is always the last line of the file and it always begins with


    To delete the last line,
    sed '$d' in > out

    --
    William Park <>
    Open Geometry Consulting, Toronto, Canada
    William Park, Aug 22, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. oNLINE bUDDY

    many-to-many XML structure

    oNLINE bUDDY, Aug 7, 2004, in forum: XML
    Replies:
    3
    Views:
    436
    oNLINE bUDDY
    Aug 9, 2004
  2. Replies:
    1
    Views:
    478
    Juan T. Llibre
    Oct 18, 2006
  3. Replies:
    1
    Views:
    445
    Jonathan Mcdougall
    Dec 6, 2005
  4. Harry Barker
    Replies:
    2
    Views:
    513
    Alf P. Steinbach
    Apr 19, 2006
  5. crea
    Replies:
    2
    Views:
    409
    Nobody
    Dec 28, 2012
Loading...

Share This Page