help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Printing in red during output from head


From: lisa-asket
Subject: Printing in red during output from head
Date: Wed, 21 Jul 2021 18:41:59 +0200 (CEST)

Have also tried to use `tput` but has not worked



    find "$fdir" -type f -name "*.org" -o -name "*.texi"  \
      -exec head -n "$n" {} \+                            \
      | sed -e 's/==>/$(tput setaf 1)==>/;s/<==/<==$(tput sgr0)/'



But with \x1B I managed to get the colouring



    find "$fdir" -type f -name "*.org" -o -name "*.texi"  \
      -exec head -n "$n" {} \+                            \
      | sed -e 's/==>/\x1B[01;31m==>/;s/<==/<==\x1B[0m/'


From: Greg Wooledge <greg@wooledge.org>
To: help-bash@gnu.org
Subject: Re: Printing in red during output from head
Date: 21/07/2021 18:36:34 Europe/Paris

On Wed, Jul 21, 2021 at 06:27:17PM +0200, lisa-asket@perso.be wrote:
> * I would like to colour the lines showing the file names

So you don't need a *specific* color? Another change to the problem
spec. But the good news is, this one actually makes it *easier* instead
of harder.



* I would like to distinguish the file name part from the other text


GNU grep can do this, although the exact mechanism is a bit
counterintuitive:

yourthing | grep --color -e ^ -e '^==>.*'



* So after calling head, I use grep.  Let's try it.


The first -e ^ tells grep to match (and therefore print) every line,
no matter what. But since it's an empty pattern, it doesn't cause every
line to be colored. The second -e pattern tells grep to match only
specific lines -- and since this pattern isn't empty, the lines that
match it will be colored.

If you actually care which color gets used, you can read the GNU grep
documentation and try to figure out how to configure it.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]