Sign in to follow this  
Followers 0
Mr_Miguel

[Batch] Strip rightmost character from each line

3 posts in this topic

Greetings.

I would like to know if it's possible, using a batch file, to strip the rightmost character from each line in a file, and if so, how? That is, for example, I would want this file:

foo|bar|xyz|

123|456|789|

To become this:

foo|bar|xyz

123|456|789

You may assume I'm using Windows XP or higher. I would also like to avoid having to write an entire new file to the disk, since the files I'm working with are quite large. Rather, I would like to modify the existing file.

Thank you in advance.

Share this post


Link to post
Share on other sites

I tried this cmd promt code,

@Echo Off
CLs
Mode 62,7
Color 9f

Set String="123|456|789|"

Echo.
Set S1=%String:~0,12%
Set S2=%String:~1,3%
Echo.
Echo %S1%
Echo %S2% 
pause

which produce

"123|456|789

123

Because you have | these in your string it causes problem

if you turn this Set S2=%String:~1,3% to this Set S2=%String:~1,4% the script just opens and closes fast.

If you where to do this Vbs and all the strings where like below

foo|bar|xyz

123|456|789

Then a simple VBS script would do.

Example Save as StringLeft.vbs

WScript.Echo Left("foo|bar|xyz|",11) & vbCrLf & Left("123|456|789|",11)

1 person likes this

Share this post


Link to post
Share on other sites

^ good, knowledgeable, concise post..

i'll rep that! :D

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.