LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Grep issue with ls --color=always on terminator (https://www.linuxquestions.org/questions/linux-general-1/grep-issue-with-ls-color%3Dalways-on-terminator-4175510028/)

Mega-X 07-03-2014 06:18 PM

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'

syg00 07-03-2014 07:09 PM

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.

Habitual 07-04-2014 09:07 AM

reported above post.

Mega-X 07-05-2014 11:57 AM

Quote:

Originally Posted by syg00 (Post 5198276)
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.

Firerat 07-05-2014 12:26 PM

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'


All times are GMT -5. The time now is 01:35 AM.