View unanswered posts | View active topics It is currently 23 Oct 2014 07:04



Post new topic Reply to topic  [ 9 posts ] 
Merge All prn File with start file name each row 
Author Message

Joined: 06 Jul 2012 11:04
Posts: 26
Post Merge All prn File with start file name each row
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


03 Aug 2012 10:06
Profile

Joined: 10 Feb 2012 02:20
Posts: 4319
Post Re: Merge All prn File with start file name each row
Try this:

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



Edited to correct error:


03 Aug 2012 10:15
Profile

Joined: 06 Jul 2012 11:04
Posts: 26
Post Re: Merge All prn File with start file name each row
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


03 Aug 2012 10:26
Profile

Joined: 10 Feb 2012 02:20
Posts: 4319
Post Re: Merge All prn File with start file name each row
I edited the post above - try it now.


03 Aug 2012 11:10
Profile

Joined: 06 Jul 2012 11:04
Posts: 26
Post Re: Merge All prn File with start file name each row
Perfect!! its work.

Thanks a lot :D


03 Aug 2012 11:19
Profile

Joined: 06 Jul 2012 11:04
Posts: 26
Post Re: Merge All prn File with start file name each row
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
)
)


18 Aug 2012 09:52
Profile

Joined: 26 Oct 2011 22:38
Posts: 1007
Location: Egypt
Post Re: Merge All prn File with start file name each row
just replace %%a with %%b
Quote:
@echo off
for %%a in (*.prn) do (
for /f "delims=" %%b in ('type "%%a"') do (
>>newfile.txt echo %%b^|%%a
)
)


18 Aug 2012 11:25
Profile

Joined: 06 Jul 2012 11:04
Posts: 26
Post Re: Merge All prn File with start file name each row
Yes, its work ...Thanks a lot for your prompt reply.


18 Aug 2012 13:16
Profile

Joined: 23 Dec 2011 13:59
Posts: 1935
Post Re: Merge All prn File with start file name each row
Hope you are actually reading the code and learning to understand what the code does.


18 Aug 2012 17:58
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 


Who is online

Users browsing this forum: Baidu [Spider], Yahoo [Bot] and 28 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Forum style by Vjacheslav Trushkin for Free Forums/DivisionCore.