Page 1 of 1

Merge All prn File with start file name each row

Posted: 03 Aug 2012 10:06
by DingDang
Hi,

I want to merge all .prn file to new txt file in folder with start file name and pipe seprated (|) in all row

have using below code but its only merging.

@echo off
copy /A *.prn Newfile.txt

requied output file is as below

(filename) | ( data of file )
ab.prn | fakjsdfla;djf;jadsf;lajdsfjasdfjalkfa
ab.prn | reirjqaejadkjfadjfoadfladsfaldjfadjsfadsjfa
123.prn | fadsjfkldjasfajsdorijerfasdfalsdfjadlsfjasfadaf
123.prn | fadsjfkldjasfajsdorijerfasdfalsdfjadlsfjasdf
123.prn | fadsjfkldjasfajsdorijerfasdfal
123.prn | fadsjfkldjasfajsdorijerfasdfalsdfjadlsfjas
123.prn | fadsjfkldjasfajsdorijerfasdfalfda54454
xyz.prn | dfadkjsfaldjsflajsdflkasdjflajsd
xyz.prn | dfadkjsfaldjsflajsdflkasdjflajsdfadfadsfadsfa
xyz.prn | dfadkjsfaldjsflajsdflkasdjflajsddafdasfdas
xyz.prn | dfadkjsfaldjsflajsdflkasdjflajsdfa
xyz.prn | dfadkjsfaldjsflajsdflkasdjflajsd21221
bbb123.prn | fjdskjfadsjfasdfjadsfasdfa2121212121
bbb123.prn | fjdskjfadsjfasdfjadsfasdfa54554545
bbb123.prn | fjdskjfadsjfasdfjadsfasdfa888

Pls help

Re: Merge All prn File with start file name each row

Posted: 03 Aug 2012 10:15
by foxidrive
Try this:

Code: Select all

@echo off
for %%a in (*.prn) do (
for /f "delims=" %%b in ('type "%%a"') do (
>>newfile.txt echo %%a^|%%b
)
)



Edited to correct error:

Re: Merge All prn File with start file name each row

Posted: 03 Aug 2012 10:26
by DingDang
Sir,

its only showing file name "|" again file name not copying data from file

need to copy all data from each file to one new file adding file name to each row of data at starting with "|".

getting output file as below with below code.

ab.prn | ab.prn
ab.prn | ab.prn
123.prn | 123.prn
123.prn | 123.prn
123.prn | 123.prn
123.prn | 123.prn
123.prn | 123.prn
xyz.prn | xyz.prn
xyz.prn | xyz.prn
xyz.prn | xyz.prn
xyz.prn |xyz.prn
xyz.prn | xyz.prn
bbb123.prn | bbb.123

Re: Merge All prn File with start file name each row

Posted: 03 Aug 2012 11:10
by foxidrive
I edited the post above - try it now.

Re: Merge All prn File with start file name each row

Posted: 03 Aug 2012 11:19
by DingDang
Perfect!! its work.

Thanks a lot :D

Re: Merge All prn File with start file name each row

Posted: 18 Aug 2012 09:52
by DingDang
Sir,

Can u pls do the small modification in below code. I just want to copy file name with "|" seprator at last column.

current output with below code as
ab.prn | fakjsdfla;djf;jadsf;lajdsfjasdfjalkfa

required output as below

fakjsdfla;djf;jadsf;lajdsfjasdfjalkfa | ab.prn

Pls help.

@echo off
for %%a in (*.prn) do (
for /f "delims=" %%b in ('type "%%a"') do (
>>newfile.txt echo %%a^|%%b
)
)

Re: Merge All prn File with start file name each row

Posted: 18 Aug 2012 11:25
by abc0502
just replace %%a with %%b
@echo off
for %%a in (*.prn) do (
for /f "delims=" %%b in ('type "%%a"') do (
>>newfile.txt echo %%b^|%%a
)
)

Re: Merge All prn File with start file name each row

Posted: 18 Aug 2012 13:16
by DingDang
Yes, its work ...Thanks a lot for your prompt reply.

Re: Merge All prn File with start file name each row

Posted: 18 Aug 2012 17:58
by Squashman
Hope you are actually reading the code and learning to understand what the code does.