edit lines in FIND comand

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Mado91
Posts: 15
Joined: 16 Mar 2019 08:03

edit lines in FIND comand

#1 Post by Mado91 » 07 Apr 2020 15:08

Hi programmers,
I'm facing the following task:

I have the file "c:\folder\a.txt" with the following content:

a
b
a
b
c

So I use the following batch:

find "a" < c:\folder\a.txt >> c:\folder\b.txt

and I obtain the c:\folder\b.txt with the following content:

a
a

Now, what if I want to add a string after every line? To obtain for example the following output:

a;
a;

is it possible?
Thanks

WiVi71
Posts: 15
Joined: 06 Jan 2020 02:33

Re: edit lines in FIND comand

#2 Post by WiVi71 » 07 Apr 2020 19:45

Mado91 wrote:
07 Apr 2020 15:08
Hi programmers,
I'm facing the following task:

I have the file "c:\folder\a.txt" with the following content:

a
b
a
b
c

So I use the following batch:

find "a" < c:\folder\a.txt >> c:\folder\b.txt

and I obtain the c:\folder\b.txt with the following content:

a
a

Now, what if I want to add a string after every line? To obtain for example the following output:

a;
a;

is it possible?
Thanks
It is possible with for command.

Code: Select all

FOR /F "tokens=*" %%A IN ('find "a" ^< C:\Users\USER\Documents\NUM.txt') DO echo %%A;>> output.txt
You can get more information from SS64.

Also, TEST_>> OUTPUT.txt will add unnecessary space at the end of every line. like this:

Code: Select all

Output:
TEST_
TEST_
to avoid extra space use TEST>> OUTPUT.txt

Mado91
Posts: 15
Joined: 16 Mar 2019 08:03

Re: edit lines in FIND comand

#3 Post by Mado91 » 08 Apr 2020 00:13

Thank a lot! It worked fine.
I tried the for comand too before asking but I was misswriting the syntax, basically because of the use of apex ^.
Thanks again

Post Reply