Using grep to find PC carriage returns

Using grep to find PC carriage returns

Post by John Webste » Thu, 05 Sep 2002 09:09:06



In Solaris 2.6, I would like to search text files in multiple directories
for the remainders of PC carriage returns (^M) using something along the
lines of :
find . -exec grep '^M' {} \;
A solution doesn't seem immediately obvious. Does anyone have a suggestion?

J.Webster

 
 
 

Using grep to find PC carriage returns

Post by Darren Dunha » Fri, 06 Sep 2002 01:01:27



> In Solaris 2.6, I would like to search text files in multiple directories
> for the remainders of PC carriage returns (^M) using something along the
> lines of :
> find . -exec grep '^M' {} \;

Is the thing between the quotes a two character sequence (a caret
followed by an M), or is it a single character (control-M)?  

As a single character, that looks a little close, but I'd do it this
way.

find . -type f -exec grep -l '^M$' {} +

In my directory, that finds some binaries and a lot of pdf files.  Using
grep in this manner shows you a file with even one hit.  It would be
nicer if it could show a file only if a certain percentage of the lines
in the file matched.  I think I could do something pretty good in perl,
but it wouldn't be a one-liner.

--

Unix System Administrator                    Taos - The SysAdmin Company
Got some Dr Pepper?                           San Francisco, CA bay area
         < This line left intentionally blank to confuse you. >

 
 
 

Using grep to find PC carriage returns

Post by Vadim V. Kouevd » Fri, 06 Sep 2002 01:36:34




> > In Solaris 2.6, I would like to search text files in multiple directories
> > for the remainders of PC carriage returns (^M) using something along the
> > lines of :
> > find . -exec grep '^M' {} \;

> Is the thing between the quotes a two character sequence (a caret
> followed by an M), or is it a single character (control-M)?

> As a single character, that looks a little close, but I'd do it this
> way.

> find . -type f -exec grep -l '^M$' {} +

> In my directory, that finds some binaries and a lot of pdf files.  Using
> grep in this manner shows you a file with even one hit.  It would be
> nicer if it could show a file only if a certain percentage of the lines
> in the file matched.  I think I could do something pretty good in perl,
> but it wouldn't be a one-liner.

^M means that instead '\n' at the and of each line in text file
there are "\r\n". Most UNIX utilities do not have power to match
those. Here is one of solutions:




unix2dos: converting file test2 to DOS format ...


asdfgh