Why can't "[[:space:]]" match Line Feed(LF) on grep command?

Solution Verified - Updated -

Issue

  • Why can't "[[:space:]]" match Line Feed(LF) on grep command?

    # cat /etc/hosts
    # Do not remove the following line, or various programs
    # that require network functionality will fail.
    127.0.0.1               localhost.localdomain localhost
    ::1             localhost6.localdomain6 localhost6
    
    # grep "[[:space:]]localhost" /etc/hosts 
    
    127.0.0.1              localhost.localdomain localhost
    ::1            localhost6.localdomain6 localhost6
    # grep "[[:space:]]localhost[[:space:]]" /etc/hosts
    #
    
  • I expect the following. Because "[[:space:]]" includes LF.

    # grep "[[:space:]]localhost[[:space:]]" /etc/hosts
    127.0.0.1               localhost.localdomain localhost
    

Environment

  • Red Hat Enterprise Linux 4

  • Red Hat Enterprise Linux 5

  • Red Hat Enterprise Linux 6

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content