Merge All prn File with start file name each row

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
DingDang
Posts: 26
Joined: 06 Jul 2012 11:04

Merge All prn File with start file name each row

#1 Post by DingDang » 03 Aug 2012 10:06

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

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

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

#2 Post by foxidrive » 03 Aug 2012 10:15

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:

DingDang
Posts: 26
Joined: 06 Jul 2012 11:04

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

#3 Post by DingDang » 03 Aug 2012 10:26

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

foxidrive
Expert
Posts: 6033
Joined: 10 Feb 2012 02:20

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

#4 Post by foxidrive » 03 Aug 2012 11:10

I edited the post above - try it now.

DingDang
Posts: 26
Joined: 06 Jul 2012 11:04

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

#5 Post by DingDang » 03 Aug 2012 11:19

Perfect!! its work.

Thanks a lot :D

DingDang
Posts: 26
Joined: 06 Jul 2012 11:04

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

#6 Post by DingDang » 18 Aug 2012 09:52

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
)
)

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

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

#7 Post by abc0502 » 18 Aug 2012 11:25

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
)
)

DingDang
Posts: 26
Joined: 06 Jul 2012 11:04

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

#8 Post by DingDang » 18 Aug 2012 13:16

Yes, its work ...Thanks a lot for your prompt reply.

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

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

#9 Post by Squashman » 18 Aug 2012 17:58

Hope you are actually reading the code and learning to understand what the code does.

Post Reply