awk misreading txt file

Good morning,

I am having a problem that I have never had before using awk. I have a txt file that obviously has clear columns and records. When I open the file in textedit, or any other program, it looks as it should, but when I check it in awk by printing the whole thing, it considers everything to be on one line. The file was generated on a mac using OS 9, and I am trying to do the scripting work on a system using OS X, Leopard. I would like to add, however, that I have done this EXACT analysis before and there were no problems reading the text file -- I did a preliminary analysis of the data mid-experiment. Now, the experiment is over, and the files are appended with all the more recent trials, so I recollected them using a flash drive and moved them to my main work station for analysis.

I have tried running DOS to Linux on the files, I have copied the text into new files and saved them, even copied into word, saved as .doc, and then exported to txt. I am baffled, and starting to think it is something awry in my awk build. Does anyone have insight into this issue?

PS, if I convert the txt files to rtf files, and then read them with awk, they look ok, except at the end of each line there is a " \ ". I thought I would just use awk to print everything except for the backslash into a new file, but then nothing can read that new file properly EXCEPT awk. I am pretty irritated. Thank you!

Mac OS places a carriage return character at the end of each line of a text file, but Unix uses a line feed character. Convert the file to a unix format with:

awk '{gsub("\r", "\n"); print $0;}' macfile.txt > unixfile.txt

Regards

Wow, that was easy enough. Thank you so much! And here I was thinking that the mac formatting was the same as Unix... good life lesson.

And just to save myself the frustration of trying and failing, to put it back into a mac-readable format, I would just reverse that:

awk '{gsub("\n", "\r"); print $0;}' unixfile.txt > macfile.txt

correct? Thank you! You definitely saved the day.

PS: Mac can read unix format. Ha, now I see my confusion come full circle.

If you ever have a question about hidden characters, there's always "vi"
open a file with vi, and then type:

:set list

This will display any hidden characters (including new line, linefeed, etc.)
To turn off the "display", type:

:set nolist

That's correct.

Or you can use

With all this help, I completed the project today! I definitely need to get vi up and running on my mac. Doesn't feel very professional working in textedit :o