LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-03-2014, 06:18 PM   #1
Mega-X
LQ Newbie
 
Registered: May 2009
Location: Italy
Distribution: LUbuntu 14.04 x86_64
Posts: 21

Rep: Reputation: 1
Grep issue with ls --color=always on terminator


Hello everybody.

If I open up a terminal (I use terminator) and I try something like

Code:
ls --color=always /dev/sda* | grep '[0-9]'
I end up with the following wrong and yellow-colored output:

Code:
/dev/sda
/dev/sda1
/dev/sda2
/dev/sda3
/dev/sda4
/dev/sda5
otherwise if I type in
Code:
ls --color=never /dev/sda* | grep '[0-9]'
I have the correct output:

Code:
/dev/sda1
/dev/sda2
/dev/sda3
/dev/sda4
/dev/sda5
Can you explain me this strange behavior? Thanks in advance.

EDIT:

The same applies if I type
Code:
ls --color=always /dev/sda* | grep '0'

Last edited by Mega-X; 07-03-2014 at 06:30 PM.
 
Old 07-03-2014, 07:09 PM   #2
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,140

Rep: Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123
Neither of the outputs is wrong - you got what you asked for. An obvious line of endeavour would be to see what the colour codes generate.
Most notably how many, and which, contains a zero character.
 
Old 07-04-2014, 09:07 AM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
reported above post.
 
Old 07-05-2014, 11:57 AM   #4
Mega-X
LQ Newbie
 
Registered: May 2009
Location: Italy
Distribution: LUbuntu 14.04 x86_64
Posts: 21

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by syg00 View Post
Neither of the outputs is wrong - you got what you asked for. An obvious line of endeavour would be to see what the colour codes generate.
Most notably how many, and which, contains a zero character.
I tried the same piece of code on a slackware terminal and I got the "right" result without the "wrong" /dev/sda, so I guess it is a matter regarding the terminal I'm using.
 
Old 07-05-2014, 12:26 PM   #5
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
It is because the colour code contains a digit

try this

Code:
ls --color=always /dev/sda* |cat -A -
You will see the extra digits in the codes
which the term renders to colour
Code:
[[0m^[[40;33;01m/dev/sda^[[0m$
[[40;33;01m/dev/sda1^[[0m$
[[40;33;01m/dev/sda2^[[0m$
[[40;33;01m/dev/sda3^[[0m$
[[40;33;01m/dev/sda4^[[0m$
[[40;33;01m/dev/sda5^[[0m$
[[40;33;01m/dev/sda6^[[0m$
Change the grep to,
Code:
grep 'a[1-9]'
However, I don't know how slackware 'fixes' it 'transparently'
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
grep issue nblarson Linux - Newbie 2 05-17-2012 09:03 AM
[SOLVED] ls grep issue Blizzard Linux - General 7 05-03-2012 03:38 AM
grep issue jack_9 Linux - Newbie 21 03-06-2012 06:02 AM
grep issue alape Linux - General 2 01-28-2012 11:49 AM
grep -v issue lleemon Linux - General 7 06-16-2003 03:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:16 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration