Page 1 of 1

edit lines in FIND comand

Posted: 07 Apr 2020 15:08
by Mado91
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

Re: edit lines in FIND comand

Posted: 07 Apr 2020 19:45
by WiVi71
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

Re: edit lines in FIND comand

Posted: 08 Apr 2020 00:13
by Mado91
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