473,729 Members | 2,348 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

deleting lines from many xml documents

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
Jul 20 '05 #1
5 1952


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/

Jul 20 '05 #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.


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

iD8DBQFBIL2lszj GeKyO8GsRAhQdAJ wMOpetLc5orjc57 nW5a3D3gg3MjACf RvRk
HWc4pIOM7pBQ2Gv B7PVnfEg=
=Y5L4
-----END PGP SIGNATURE-----

Jul 20 '05 #3
Grep for windows (use version 2.2)

http://www.wingrep.com/download.html
--
---------------------------------
Trevor Lowing
Satellite Beach, Fl

tlowing@-removenospam-lowing.org
---------------------------------
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(VBScr ipt/JScript/WSH/XML)?
http://www.DevGuru.com
http://cwashington.netreach.net/
http://developer.irt.org/script/script.htm
---------------------------------
Jul 20 '05 #4
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" <tl*****@lowing .org> schrieb im Newsbeitrag
news:41******@c pns1.saic.com.. .
Grep for windows (use version 2.2)

http://www.wingrep.com/download.html
--
---------------------------------
Trevor Lowing
Satellite Beach, Fl

tlowing@-removenospam-lowing.org
---------------------------------
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(VBScr ipt/JScript/WSH/XML)?
http://www.DevGuru.com
http://cwashington.netreach.net/
http://developer.irt.org/script/script.htm
---------------------------------

Jul 20 '05 #5
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
Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
43458
by: Behrang Dadsetan | last post by:
Hi all, I would like deleting specific characters from a string. As an example, I would like to delete all of the '@' '&' in the string 'You are ben@orange?enter&your&code' so that it becomes 'benorange?enteryourcode'. So far I have been doing it like: str = 'You are ben@orange?enter&your&code' str = ''.join()
5
2734
by: Brian | last post by:
Hello all.. Am working on an Air Hockey game... have an table loaded into a picture box. The borders of the table are slightly slanted. Am using hit testing lines with GDI+ to manipulate the puck moving around. I want the puck is bounce when it hits a border (specified by the hitlines). Retreieved some info on hit testing lines from Bob Powell's GDI+ FAQ (very useful!) but i'm fairly new at the idea of hit testing and am
6
4560
by: Martin Bischoff | last post by:
Hi, I'm creating temporary directories in my web app (e.g. ~/data/temp/temp123) to allow users to upload files. When I later delete these directories (from the code behind), the application restarts and all active sessions are terminated. This error is also described in detail here:...
5
2357
by: Patrick Vanden Driessche | last post by:
Hi All, I'm currently writing an in-house Form validation framework (WinForms) which is based on 'Component'-inheriting object. So basically, I have a small hierarchy. FormValidator +-- ControlValidator +--ValidationRule
5
2686
by: George | last post by:
VB.net 2003 standard, XP windows home edition. Installed first application OK today. When I removed the application via Control Panel, there were no problems and the app folders were deleted. But when I installed the app from a CD-ROM (Release folder is in D:), when I remove the app in Control Panel these problems occur: Control Panel does not delete the application folders. When I try to delete them I get message "Cannot delete file:...
13
2462
by: programming | last post by:
how do i delete from a text file 1 of the following lines: jon|scott adam|smith <--delete paul|clark say i would like to delete the middle line of this txt, in member.txt what php code or logic would help me accomplish this?
10
4594
by: kriz4321 | last post by:
I have many files in a dirctory in which I need to make the common subsitution. I need to delete all lines between two matched patterns I need to match a line having words " chkstats to capture " starting from this line (Say it occurs at line 40) to another line "Failure to pull stats" (which may come in line no 100) and there is close brace('}") at the next line which also needs to be removed.
4
1536
by: blackice | last post by:
Hello All, i have a Perl Script that deleting Zones from named.conf file and here is the script #!/usr/bin/perl -w use strict; print "please enter the domain name: "; chomp (my $targetdomain = <STDIN>);
1
1769
by: Kyosuke18 | last post by:
Hi everyone, I have a problem in deleting a data that is connected on the database.. I tried this code but it shows me an error: Run-time error '-2147217900(80040e14)': Syntax error in string in query expression 'ID=". Here is the code that i did: Dim cn As New ADODB.Connection Dim rs As New ADODB.Recordset Dim ab As String cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Administrator\My...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9142
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8148
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4525
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2680
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.