Computing.Net > Forums > Programming > Create a copy of unix style file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Create a copy of unix style file

Reply to Message Icon

Name: ksuchetan
Date: October 8, 2008 at 11:35:45 Pacific
OS: Windows XP
CPU/Ram: 2gb
Comment:

Hi,

I receive a file from Unix server to my windows server,this file is unix style

I try to create a copy of this file via windows batch script:
@echo off
setLocal EnableDelayedExpansion

CD%1
if exist "A_COMBINED.TXT" del "A_COMBINED.TXT"
if exist "B_COMBINED.TXT" del "B_COMBINED.TXT"
copy *A A_COMBINED
copy *B B_COMBINED

where A file actual name is 20081003_A
and B file actual name is 20081003_B

When i run the script the file is copied but at the end it has an carriage return character.


Please help me I am new to DOS scripting I don't want this carriage character added in the end because i have job which aborts due to this extra carriage return value in the end of the file.

Thanks In Advance

Thanks In Advance



Sponsored Link
Ads by Google

Response Number 1
Name: Razor2.3
Date: October 8, 2008 at 17:41:48 Pacific
Reply:

copy /b *A A_COMBINED
copy /b *B B_COMBINED


0

Response Number 2
Name: FishMonger
Date: October 8, 2008 at 17:45:14 Pacific
Reply:

Exactly what do you mean by "this file is unix style"?

Exactly how are you determining that the carriage return is being added during the copy process and not from the file transfer process?

How are you transferring the file between the servers? If via an ftp connection, are you transferring in ascii mode or binary?


0

Response Number 3
Name: ksuchetan
Date: October 14, 2008 at 10:31:39 Pacific
Reply:

well by unix style file i mean my file doesnot have new line character associated so

first file has

record1
record2

and second file has

record3
record4

the above command combines the file as follows
record1
record2 record3
record4


whereas i want as
record1
record2
record3
record4

Thanks In advance

Thanks In Advance


0

Response Number 4
Name: klint
Date: October 14, 2008 at 10:59:00 Pacific
Reply:

The usual definition of a Unix file is that each of its lines is terminated by a single LF character (instead of CR LF on Windows.) Your file has a different problem. Its last line is not terminated. Therefore, when you append the next file to it, it simply continues the last line of the previous file.

This can be fixed thus:

Prior to combining all your files into one with copy/b, add an empty line to the end of each file using the following command:

for %%f in (*A) do (echo.>%%f)

Warning: make sure all files matching "*A" are text files, and that they all have unterminated last lines. If they don't, you'll be adding an unwanted blank line at the end.


0

Response Number 5
Name: ksuchetan
Date: October 14, 2008 at 11:07:06 Pacific
Reply:

My files are not txt files and when executed this command on the files the files had no text in it.:(

is there any way I can add newline character at the end of the file

I have tried this script

for /f "tokens=* delims= " %%t in ('dir/b/a-d *%2*') do (
type %%t >> COMBINED.TXT
)
)

but I face the same issue as above.

Please guide

Thanks for your time and patience

Thanks In Advance


0

Related Posts

See More



Response Number 6
Name: klint
Date: October 14, 2008 at 16:32:42 Pacific
Reply:

> My files are not txt files

I meant text files, as opposed to binary files. It doesn't matter what their filename extension is, as long as they're just plain text, not word documents, not PDFs etc.

> and when executed this command on the
> files the files had no text in it.:(

Oops, sorry about that, I meant to write

echo.>>%%f

not echo.>%%f as that would overwrite the file instead of appending a line to it. I hope you tested this on copies, rather than the originals.

Once you've added the blank line to all your files (assuming they all end with an unterminated line) then the previously mentioned copy/b command will merge them.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Create a copy of unix style file

Copying a bunch of buried files to another di www.computing.net/answers/programming/copying-a-bunch-of-buried-files-to-another-di/19300.html

create a log for a batch file www.computing.net/answers/programming/create-a-log-for-a-batch-file/18410.html

Create a Functional Listbox www.computing.net/answers/programming/create-a-functional-listbox/5062.html