Hi all forks,
So glad to be in this group and got some replies from you regarding this topic
"have a list of folder containing one file for each folder, need to find this file path in another folder/subfolder"
Now I had a solution for it but I need to trim off all the ==> for each line in one txt file as below:
==> 500007011000.S3S
==> 500011011000.S3S
==> 500016011000.S3S
==> 500072010400.S3S
==> 500136010100.S3S
==> 500022010300.S3S
==> 500007011000.S3S
==> 500008011000.S3S
==> 500019011200.S3S
==> 500008011000.S3S
==> 500009011000.S3S
==> 500012011000.S3S
==> 500014011000.S3S
==> 500028011201.S3S
==> 500135010100.S3S
==> 500143010002.S3S
==> 500142010100.S3S
==> 500144010100.S3S
==> 500006011000.S3S
==> 500007011000.S3S
==> 500008011000.S3S
==> 500009011000.S3S
==> 500010011000.S3S
==> 500011011000.S3S
==> 500012011000.S3S
==> 500014011000.S3S
==> 500016011000.S3S
==> 500134010100.S3S
==> 500028011201.S3S
==> 500129010200.S3S
==> 500072010400.S3S
==> 500135010100.S3S
==> 500143010002.S3S
I need to be as this in new txt file
500007011000.S3S
500011011000.S3S
500016011000.S3S
500072010400.S3S
500136010100.S3S
500022010300.S3S
500007011000.S3S
500008011000.S3S
500019011200.S3S
500008011000.S3S
500009011000.S3S
500012011000.S3S
500014011000.S3S
500028011201.S3S
500135010100.S3S
500143010002.S3S
500142010100.S3S
500144010100.S3S
500006011000.S3S
500007011000.S3S
500008011000.S3S
500009011000.S3S
500010011000.S3S
500011011000.S3S
500012011000.S3S
500014011000.S3S
500016011000.S3S
500134010100.S3S
500028011201.S3S
500129010200.S3S
500072010400.S3S
500135010100.S3S
500143010002.S3S
Thanks so much again for all your kind replies
William
trim off some characters of lines in txt file
Moderator: DosItHelp
Re: trim off some characters of lines in txt file
Problem solved ! instead of using % I used ! it works! Could anyone tell me why ?
Code: Select all
@echo off
setlocal enabledelayedexpansion
for /f "delims=" %%i in (sch_repl_list_after.txt) do (
set line=%%i
echo !line:~6, 16! >>removed_str.txt
)
Re: trim off some characters of lines in txt file
The command line interpreter expands percentage variables (%var%) before executing a command.
So a block ("( command+ )") is executed after the percentage variable was expanded.
Setting the variables value won't affect the result of the earlier percentage expansion.
The exclamation mark variables are expanded right before an atomic command is executed (delayed expansion), so it could expand to the right value, set with a previous atomic command.
penpen
So a block ("( command+ )") is executed after the percentage variable was expanded.
Setting the variables value won't affect the result of the earlier percentage expansion.
The exclamation mark variables are expanded right before an atomic command is executed (delayed expansion), so it could expand to the right value, set with a previous atomic command.
penpen
Re: trim off some characters of lines in txt file
Thanks Penpen! How to make the above code works by using % if possible
-
- Posts: 128
- Joined: 23 May 2016 15:39
- Location: Spain
Re: trim off some characters of lines in txt file
Code: Select all
echo !line:~6,16!
can be
Code: Select all
call echo %%line:~6:16%%
note double percent sign to force call evaluate the term inside. but performance will be worst than using delayed expansion (think about a large file to process)
also, if performance is in your mind
Code: Select all
for ... do (
echo whatever>>somefile.txt
)
will open and close the file every time, where
Code: Select all
>somefile.txt (
for ... (
echo whatever
)
)
Re: trim off some characters of lines in txt file
Thanks so much elzooilogicofor your detailed explanation with sample. that helps us a lot in terms of why that works that way...