How to chop off substrings in the txt file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
goodywp
Posts: 250
Joined: 31 Jul 2017 09:57

How to chop off substrings in the txt file

#1 Post by goodywp » 09 Jan 2018 14:26

Hi All,
Happy New Year to you all!!!
It is a great forum here in which I can have your help....

I have a txt file showing like this:
500006011000.S3S
500007011000.S3S
500008011000.S3S
500009011000.S3S
500010011000.S3S
500012011000.S3S
500014011000.S3S
500016011000.S3S
500134010100.S3S
500028011201.S3S
500129010200.S3S
500015011000.S3S
500142010100.S3S
500144010100.S3S

Now I would like to chop off some substrings and become sth. like this in another txt file: Basically keep first 6 digits then using * for the rest and keep .S3S at the end.
500006*.S3S
500007*.S3S
500008*.S3S
500009*.S3S
500010*.S3S
500012*.S3S
500014*.S3S
500015*.S3S
500016*.S3S
500028*.S3S
500129*.S3S
500134*.S3S
500142*.S3S
500144*.S3S

Thanks

Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

Re: How to chop off substrings in the txt file

#2 Post by Squashman » 09 Jan 2018 14:50

This is basic string manipulation as described here. Lots of examples for you to look at.

Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

Re: How to chop off substrings in the txt file

#3 Post by Squashman » 09 Jan 2018 14:54

Let take a trip back on memory lane.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How to chop off substrings in the txt file

#4 Post by aGerman » 09 Jan 2018 14:55

Untested:

Code: Select all

setlocal EnableDelayedExpansion
>"another.txt" (
  for /f "usebackq delims=" %%i ("original.txt") do (
    set "n=%%~ni"
    echo !n:~,6!*%%~xi
  )
)
endlocal
Steffen

goodywp
Posts: 250
Joined: 31 Jul 2017 09:57

Re: How to chop off substrings in the txt file

#5 Post by goodywp » 09 Jan 2018 15:08

aGerman wrote:
09 Jan 2018 14:55
Untested:

Code: Select all

setlocal EnableDelayedExpansion
>"another.txt" (
  for /f "usebackq delims=" %%i ("original.txt") do (
    set "n=%%~ni"
    echo !n:~,6!*%%~xi
  )
)
endlocal
Steffen
Thanks Steffen!
I use this code:

Code: Select all

@echo off
call C:\auto_pkg_build\Scripts\scheme_replace\varconfig.cmd
set VAR14=%VAR14:~8%

cd "C:\auto_pkg_build\Tools\PACKAGER\S3S\TELIUM3\%VAR14%"

setlocal EnableDelayedExpansion
>"trim_generic.txt" (
  for /f "usebackq delims=" %%i ( "generic.txt" ) do (
    set "n=%%~ni"
    echo !n:~,6!*%%~xi
  )
)
endlocal
I got this error:
("generic.txt" was unexpected at this time.

Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

Re: How to chop off substrings in the txt file

#6 Post by Squashman » 09 Jan 2018 15:55

Missing the IN.

goodywp
Posts: 250
Joined: 31 Jul 2017 09:57

Re: How to chop off substrings in the txt file

#7 Post by goodywp » 09 Jan 2018 16:13

Squashman wrote:
09 Jan 2018 15:55
Missing the IN.
Thanks for your reminding and works....
BTW, I used the memory line you mentioned and modified code to be like this

Code: Select all

@echo off 
call C:\auto_pkg_build\Scripts\scheme_replace\varconfig.cmd
set VAR14=%VAR14:~8%
cd "C:\auto_pkg_build\Tools\PACKAGER\S3S\TELIUM3\%VAR14%"

if exist trim_generic.txt (del trim_generic.txt)
setlocal enabledelayedexpansion

for /f "delims=" %%i in (generic.txt) do (
set line=%%i 
echo !line:~,6!*.S3S>>trim_generic.txt
)
And it also works fine as expected. :D

Post Reply