Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I use

sed -i "s,.*%.*,$(tput setaf 1)&$(tput sgr0),g" A.log

the whole line vanishes and when I use

sed -i "s,^%.*,$(tput setaf 1)&$(tput sgr0),g" A.log

only the first character(%) turns red.

What should I do?

EDIT : Actually the whole line doesn't vanish, I was using more but when I used less -R I saw this (with a control M character) and % in red color.

 % Invalid input detected at '^' marker.^M
share|improve this question
up vote 3 down vote accepted

Something like this ?

sed -i "s/^%.*$/$(tput setaf 1)\\0$(tput sgr0)/" A.log 

And use cat -v file for displaying content without parsing colors.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.