Operating System - HP-UX
1752604 Members
4663 Online
108788 Solutions
New Discussion юеВ

Re: Little help with grep

 
SOLVED
Go to solution

Little help with grep

Does anyone know if grep and search a text file looking for the carriage return "^M" sequence? Your help will be much appreciated. Thanks to all you grep-ping gurus.
5 REPLIES 5
Vincenzo Restuccia
Honored Contributor

Re: Little help with grep

Try grep -i "^M"
Vincenzo Restuccia
Honored Contributor

Re: Little help with grep

Sorry foe bad reply,I hope this help:

The grep command searches the input text files (standard input default) for lines matching a pattern. Normally, each line found is copied to the standard output. grep supports the Basic Regular Expression syntax (see regexp(5) ). The -E option (egrep) supports Extended Regular Expression (ERE) syntax (see regexp(5) ). The -F option (fgrep) searches for fixed strings using the fast Boyer-Moore string searching algorithm. The -E and -F options treat newlines embedded in the pattern as alternation characters. A null expression or string matches every line.
John Poff
Honored Contributor

Re: Little help with grep

I've had some success with this:

grep -E '\r' file.txt

John Poff
Honored Contributor

Re: Little help with grep

Actually, it works without the -E:

grep '\r' file.txt

Bill Hassell
Honored Contributor
Solution

Re: Little help with grep

Note that ^M is displayed by vi as an indication that you are editing an ASCII file produced by a PC. It is vi's way of showing you a unexpected special character. It does not appear in the file itself as the 2 characters: ^ and M If you use cat -v, you can see the same special character representation (and probably the ^Z at the end).

To quickly fix these PC files, use dos2ux as in:

dos2ux MyFileName > fixed_up_file

These files will always exist if network sharing is used (Samba) or ASCII files are ftp'ed in binary format rather than ASCII.


Bill Hassell, sysadmin