James Philp
Derek Fountain
wrote: James Philp
wrote: I have a (huge) file which contains Matlab style 'NaN' for missing data and I need to make it Gauss readable by replacing all the 'NaN' with the symbol '.'.
Using everyone's favourite swiss army chainsaw:
perl -pi -e 's/NaN/\./' file.csv
Take a backup first!
Thanks a lot. Brilliant little trick. However it only does it for the first row of the data.
Btw, where do you learn these things from?
Another solution: sed s/NaN/\./g file.csv > file_fixed.csv It substitutes every instance of "NaN" on every line and doesn't alter the original file. My favorite resource for such questions is _Unix Power Tools_ 3nd ed., by Shelley Powers, Jerry Peek, Tim O'Reilly, and Mike Loukides. It has a wealth of (mostly command line) tips and tricks for *nix systems. The coverage of Perl (and its more modern substitute, Python) is brief, but it's a peerless general reference (I bought the 1st edition before I started using Linux). http://www.oreilly.com/catalog/upt3/ BTW, I reformatted your post into the "standard" form. Much easier to read. HTH, -rex -- If at first you don't succeed, try and try again- then give up, there's no use being a damn fool about it. --W.C.Fields