Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

1 Answer 1

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
add comment

Your Answer

 
discard

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.