I am working on a project that requires me to write a script that operates on a bunch of text files. When I try
I see a bunch of ^M's everywhere. Some Googling tells me that this is because the files have a DOS fileformat and found the following fixes:
or
Alas, neither of these approaches seems to work. When I open the file in gedit, everything is formatted appropriately and if I use gedit to save the file as file1.txt, the new file is fine when I do
too. Is there anything I can do to fix the file from command line?
---------- Post updated at 03:05 AM ---------- Previous update was at 03:00 AM ----------
Sorry folks, I just realized that the files are Mac OS Classic file format and not DOS. I wrote a little awk script that fixes things now. I'm very sorry for the confusion. I'd appreciate it if a moderator can remove the thread.
More completeness: Try "recode" to convert between a wide variety of encodings. Can be installed using macports on the Mac.
lists all encodings it knows about
converts between "old" encoding and "new" one.
That approach will add an extra blank line during the conversion, because after converting the last \r to \n, the awk print statement will add another \n.
If the text file is very large, the conversion will also require a large amount of memory, because awk reads until it finds a \n record separator (which is absent). With some awks, if there's a line length limit, even if you had sufficient memory, the attempt would fail.
In my opinion, the tr utility is tailor-made for this task. It's widely available, simple to use, will not add an extra blank line, and will not consume large amounts of memory even when dealing with monstrous files.
If you insist on using awk, the following is a much better approach (it won't add the extra blank line nor slurp the entire file into memory unless the entire file is one \r-terminated line):
My critique aside, thank you for reporting back with your solution. It's always good (and helpful for those who will search the forum in the future) to know how problems were resolved.
Hi,
This is my DOS Batch file.
@echo off
echo "Program Name :" %0
rem echo "Next param :" %1
echo "Next param :" "Username/Password"
echo "User Id :" %2
echo "User Name :" %3
echo "Request ID ... (4 Replies)
Hi,
I am new to shell scripting and exploring it , I have developed few sample shell script but I have developed them on windows xp notepad and then saving them on folder and then testing them on cywgin and running perfectly...but these scripts are in dos format and I want to convert them in unix... (1 Reply)
Is any one who know a good tutorial for Unix bash script and Ms-Dos scipt??
if yes, if is possible to upload it or give me the link???
What is the difference betwwen uvix and ms-dos script?? (1 Reply)
hi eveybody,
i use sco unix as server and dos as client . how i can connect from unix server to dos client ( how to telnet to dos and run commands?)?
thanks. (8 Replies)
hi eveybody,
i use sco unix as server and dos as client . how i can connect from unix server to dos client ( how to telnet to dos and run commands?)?
thanks. (1 Reply)
hi eveybody,
i use sco unix as server and dos as client . how i can connect from unix server to dos client ( how to telnet to dos and run commands?)?
thanks. (1 Reply)
Is there a tool available to convert UNIX (BASH Shell) scripts to DOS scripts?
I understand that DOS scripting is far inferior to unix scripting, and therfore this conversion may not be possible.
Alternativley, perhaps I could convert my Unix scripts to C... then compile it for a windows... (2 Replies)
Hi friends!
I am having some simple shell script files to build postgresql database and all. Now i want to convert those scripts to dos batch scripts(to run on windows XP/2000/NT) because there is no need of unix emulation for latest release of postgresql. Please somebody help me. (1 Reply)
I know nothing of unix and didn't know where to start. I've heard of a DOS to Unix translator, and since I know DOS pretty well, I thought that this program would be perfect. Any help you could give me would be appreciated.
Bryan (1 Reply)