Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7672851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:22:46+00:00 2026-05-31T16:22:46+00:00

Grepping non printable characters doesn’t seem to work for carriage return (control key ^M).

  • 0

Grepping non printable characters doesn’t seem to work for carriage return (control key ^M).

usr@R923047 ~
$ head -3 test.ctl
row 1
row 2
row 3
usr@R923047 ~
$ head -3 test.ctl | cat -nv
     1  row 1^M
     2  row 2^M
     3  row 3
usr@R923047 ~
$ head -3 test.ctl | grep '[^[:print:]]'

usr@R923047 ~
$ head -3 test.ctl | grep '[[:cntrl:]]'

usr@R923047 ~
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T16:22:47+00:00Added an answer on May 31, 2026 at 4:22 pm

    According to the grep man-page, you can specify -U or --binary to:

    Treat the file(s) as binary. By default, under MS-DOS and MS-Windows, grep guesses the file
    type by looking at the contents of the first 32KB read from the file. If grep decides the
    file is a text file, it strips the CR characters from the original file contents (to make
    regular expressions with ^ and $ work correctly). Specifying -U overrules this guesswork,
    causing all files to be read and passed to the matching mechanism verbatim; if the file is a
    text file with CR/LF pairs at the end of each line, this will cause some regular expressions
    to fail. This option has no effect on platforms other than MS-DOS and MS-Windows.

    So:

    $ head -3 test.ctl
    row 1
    row 2
    row 3
    $ head -3 test.ctl | cat -nv
         1  row 1^M
         2  row 2^M
         3  row 3
    $ head -3 test.ctl | grep '[^[:print:]]'
    
    $ head -3 test.ctl | grep '[[:cntrl:]]'
    
    $ head -3 test.ctl | grep -U '[^[:print:]]'
    row 1
    row 2
    
    $ head -3 test.ctl | grep -U '[[:cntrl:]]'
    row 1
    row 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In /usr/include , I tried grepping for GL gl and OpenGL .. .but can't
Looking for a nifty helper function/method for grepping through all defined tables, columns, stored
I am basically grepping with a regular expression on. In the output, I would
I'm looking for python modules that can help with grepping C++ code. I have
Can anyone point me to the definition of strlen() in GCC? I've been grepping
I'm grepping through a large pile of code managed by git, and whenever I
Having trouble with grepping and cutting at the same time I have a file
I've seen some examples of grepping lines before and after, but I'd like to
What is the difference between these commands? Why does the first match, but grepping
I am grepping an XML File, which gives me output like this: <tag>data</tag> <tag>more

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.