General discussion

Locked

Concatenating files In DOS

By brian ·
I have a bunch of files that I need to add a single line to the beginning of. I know I can do it with "copy file1+file2 newfilename.csv". However, I want to use "file2" with a new extension as the destination. I have tried "copy header.txt+*.aqh *.csv" but I end up with one huge "header.csv" file instead of individual *.csv files.

Any scripting guru's that can help me out?

This conversation is currently closed to new comments.

10 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Concatenating files In DOS

by Uch In reply to Concatenating files In DO ...

To combine a series of files that have ".txt" extensions with several corresponding ".aqh", ".cvs" files to make new files with the same file names but with ".cvs" extensions (ie "header.txt" is combined with "file1.aqh" to form "file1.cvs", and so on).
Try using ==> COPY header.txt + *.aqh *.cvs

Good Luck.

Collapse -

Concatenating files In DOS

by brian In reply to Concatenating files In DO ...

Um, read my post again.

Collapse -

Concatenating files In DOS

by davidfranks78 In reply to Concatenating files In DO ...

aT THE dos PROMPT The command:

FOR %X IN (*.CSV) DO TYPE FILE.TXT >> %X

will append the contents of "file.txt" at the end of each file having the extension as ".csv"

Hope this helps.

Collapse -

Concatenating files In DOS

by brian In reply to Concatenating files In DO ...

Thats a good start, but I need the file pre-pended, not appended. Your method will put the header on the end.

Thanks,
Brian

Collapse -

Concatenating files In DOS

by davidfranks78 In reply to Concatenating files In DO ...

aT THE dos PROMPT The command:

FOR %X IN (*.CSV) DO TYPE FILE.TXT >> %X

will append the contents of "file.txt" at the end of each file having the extension as ".csv"

Hope this helps.

Collapse -

Concatenating files In DOS

by davidfranks78 In reply to Concatenating files In DO ...

Well, this is interesting.
Here's one more try:
If you want to use only DOS, I can think of doing doing it in 3 steps. (You need MS word also)

Step 1:

DIR *.CSV > A_FILE.BAT

This will create a file "A_FILE.BAT" with the list of all the ".csv" files.

Step 2 (part A):
Open "A_FILE.BAT" in Word and
form each line as:

COPY FILE.TXT + FILE1.CSV FILE1.XYZ
COPY FILE.TXT + FILE2.CSV FILE2.XYZ

and so on for all the .csv files...

COPY FILE.TXT + FILEn.CSV FILEn.XYZ

Step 2 (part B):

Run "A_FILE.BAT" at the DOS prompt

Step 2 (part C):

Copy all the existing .csv files somewhere safe and delete it from the current location.

Step 3:

REN *.xyz *.csv

(Step 2 may be a bit tedious, but if you know how to use macros in Word, you can make it a bit easier)

Sorry I can't think of anything better at the moment.

All the best.

Collapse -

Concatenating files In DOS

by brian In reply to Concatenating files In DO ...

Poster rated this answer

Collapse -

Concatenating files In DOS

by davidfranks78 In reply to Concatenating files In DO ...

Well, this is interesting.
Here's one more try:
If you want to use only DOS, I can think of doing doing it in 3 steps. (You need MS word also)

Step 1:

DIR *.CSV > A_FILE.BAT

This will create a file "A_FILE.BAT" with the list of all the ".csv" files.

Step 2 (part A):
Open "A_FILE.BAT" in Word and
form each line as:

COPY FILE.TXT + FILE1.CSV FILE1.XYZ
COPY FILE.TXT + FILE2.CSV FILE2.XYZ

and so on for all the .csv files...

COPY FILE.TXT + FILEn.CSV FILEn.XYZ
Step 2 (part B):

Run "A_FILE.BAT" at the DOS prompt

Step 2 (part C):

Copy all the existing .csv files somewhere safe and delete it from the current location.

Step 3:

REN *.xyz *.csv

(Step 2 may be a bit tedious, but if you know how to use macros in Word, you can make it a bit easier)

Sorry I can't think of anything better at the moment.

All the best.

Collapse -

Concatenating files In DOS

by brian In reply to Concatenating files In DO ...

Poster rated this answer

Collapse -

Concatenating files In DOS

by brian In reply to Concatenating files In DO ...

This question was closed by the author

Back to Windows Forum
10 total posts (Page 1 of 1)  

Related Discussions

Related Forums