DosTips.com

A Forum all about DOS Batch
It is currently 30 Aug 2016 03:04

All times are UTC-06:00




Post new topic  Reply to topic  [ 9 posts ] 
Author Message
PostPosted: 03 Aug 2012 10:06 
Offline

Joined: 06 Jul 2012 11:04
Posts: 26
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


Top
   
PostPosted: 03 Aug 2012 10:15 
Offline
Expert

Joined: 10 Feb 2012 02:20
Posts: 5913
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:


Top
   
PostPosted: 03 Aug 2012 10:26 
Offline

Joined: 06 Jul 2012 11:04
Posts: 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


Top
   
PostPosted: 03 Aug 2012 11:10 
Offline
Expert

Joined: 10 Feb 2012 02:20
Posts: 5913
I edited the post above - try it now.


Top
   
PostPosted: 03 Aug 2012 11:19 
Offline

Joined: 06 Jul 2012 11:04
Posts: 26
Perfect!! its work.

Thanks a lot :D


Top
   
PostPosted: 18 Aug 2012 09:52 
Offline

Joined: 06 Jul 2012 11:04
Posts: 26
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
)
)


Top
   
PostPosted: 18 Aug 2012 11:25 
Offline

Joined: 26 Oct 2011 22:38
Posts: 1007
Location: Egypt
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
)
)


Top
   
PostPosted: 18 Aug 2012 13:16 
Offline

Joined: 06 Jul 2012 11:04
Posts: 26
Yes, its work ...Thanks a lot for your prompt reply.


Top
   
PostPosted: 18 Aug 2012 17:58 
Offline
Expert

Joined: 23 Dec 2011 13:59
Posts: 3169
Hope you are actually reading the code and learning to understand what the code does.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 9 posts ] 

All times are UTC-06:00


Who is online

Users browsing this forum: Bing [Bot] and 12 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® Forum Software © phpBB Limited