• 0

[Batch] Strip rightmost character from each line


Question

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.

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

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)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.