It is currently Tue, 07 Dec 2021 03:37:01 GMT

Author Message
 Using grep to find PC carriage returns
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?


 Sun, 20 Feb 2005 08:09:06 GMT   
 Using grep to find PC carriage returns

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

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.

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

 Mon, 21 Feb 2005 00:01:27 GMT   
 Using grep to find PC carriage returns

^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:

root@digi # echo qwerty > test1
root@digi # echo asdfgh > test2
root@digi # unix2dos test2
unix2dos: converting file test2 to DOS format ...
root@digi # cat test1 test2 > test
root@digi # perl -ne 'if(m/\r\n$/ms){print;}' test

 Mon, 21 Feb 2005 00:36:34 GMT   
   [ 3 post ] 

Similar Threads

1. Using grep to find PC carriage returns

2. How to grep Carriage Return character

3. Using ed to remove Carriage Returns from a file

4. remove carriage return line feed using tr

5. Using return carriage with LiveWire/Informix

6. echo with CARRIAGE RETURN

7. cups and carriage returns

8. Another simple queries - no carriage return when printing - funny format

9. strip carriage return

10. Adding a carriage return.

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software