Sorry remove the /c there... thats to count the number of lines. It should have been /I (case insensitive).
Steve
Main Topics
Browse All TopicsI have a number of users on my network who each have a text file(XML) that needs to have the last line of the file removed.
I want to use a batch file to get this done as quickly as possible.
Every users file last line contains "</profiles>" without the quotes.
Attached is a sample of a users XML file I will be working with.
Thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I get an error stating the system cannot find the file specified.
Let me set back and explain more fully what I am trying to do.
I have 3 files.
UserProfiles.xml (Located in the users Documents and settings)
profileBuilder.bat (Located on the server and the bat that I am trying to create)
DefaultProfiles.txt (text contains more xml)
I want to removing the last line of the xml file I originally posted and appending the text in the attached code snippet which is more XML which includes the </profiles> closing tag.
I have the appending code correct and I have all the paths to make sure that the user running the script is the only one that will have their XML file changed.
Hope this clarifies what I am trying to do.
That works actually just fine with for /f. Simply save the script below as "RemoveLastLine.cmd" or Whatever.cmd.
The script expects the file to be shortened as first argument (enclose in double quotes if the path contains a space).
If you want to hardcode the file, you can do so in line 3.
A backup file will be created.
Business Accounts
Answer for Membership
by: dragon-itPosted on 2009-07-06 at 12:13:41ID: 24788291
well the easiest way to remove a specific line when it can be uniquely identified like this is to use a find command:
del textfile.old 2>NUL
rename textfile.xml textfile.old
type textfile.old | find /v /c "/profiles" > textfile.xml
rem del textfile.old
Any other processing of xml type files line by line with dos is going to be "interesting" due to the use of the < and > chars.
Steve