views:

78

answers:

1

Here's the statement I'm running:

grep -i -H 'ConfigureControls' *.as

Note that I'm forcing file names with the -H flag.

What I get back is:

}       }   trac}   }   this.chairControls.debug.appendText("\nAn error occured when communicating with server:\n" + err.message);l);his.chairXML.storeResult;
{ackage {ublic cpublic frequest = new URLRequest(this.chairXML.store);to: " + this.chairXML.store;noll

No filename, and the text also looks very mangled (package has become {ackage, for example). What's going on?

+2  A: 

It sounds like you're grepping old Mac (OS <= 9) CR eol-style files on a machine that's expecting LF (unix) or CR/LF (DOS/Windows).

In that case, it's actually grepping properly but your terminal is interpreting the CR newlines as "move the cursor to the start of the line" without advancing to an empty line while displaying.

If you're on a unix-like system (OSX should work too), try converting the eol-style:

grep 'pattern' file | tr '\r' '\n'

If that works, you can actually convert the file's eol-style with:

tr '\r' '\n' < file.as > fixed-file.as
scribble
Is there a fix besides going into every single file and changing the line endings?
Goose Bumper
Most modern editors have settings for that. Make sure it's saving as Unix (or DOS even). http://en.wikipedia.org/wiki/Newline has more information and suggested conversion programs.
scribble
Also, if you are transferring the files from a non-Unix system to Unix with FTP, make sure your client is set to transfer in ASCII mode for .as files, it should automatically convert the eol-style.
scribble
Unfortunately, piping to tr doesn't work – it just prints out all the .as files in the directory. I think my best bet at this point would be to write a shell script that implements your second suggestion.
Goose Bumper
There are links to converter programs at the Wikipedia link. Install flip and you can just pass it a wildcard, or `find . -name '*.as' -print0 | xargs -0 flip -u` to convert everything below the current directory (or change . to a specific path).
scribble