Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grepping for carriage returns and line feeds

Status
Not open for further replies.

Padre764

Programmer
Jul 30, 2002
10
US
Hello,

I am trying to write a ksh script to search text files for carrige returns (\r) and line feeds (\n). I need to find the lines have \r\n versus the lines that have just \n. I know that I can run dos2unix to clean up the file but I want to know beforehand what lines this is going to effect. I have tried using grep \r foo.foo but it is just returning everything in the foo.foo file. I know that foo.foo has some lines that have \r\n and some that have just \n (by looking at foo.foo with od -c). I have also tried grep \\r foo.foo and get the same results. It seems like it should be a straight forward thing to do but it has my whole team stumped.

Thanks for the help.
 
Try this:
Code:
cr=$(echo "\r\c")
grep -e "${cr}"'$' foo.foo

Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top