If I use the command below which colors the lines output in yellow, it essentially turns less into cat, printing out the entire file and disabling all of the features I need with less, such as stopping at page breaks, allowing navigation, etc.. Most of the arguments that you can use to manipulate less with are also ignored. Is there a way to prevent a sed color sequence from breaking less's features?

less file | sed -e 's/\(.*DATA.*\)/\o033[93m\1\o033[39m/'

Perhaps you meant to use less on the output of sed, rather than the reverse:

sed -e 's/\(.*DATA.*\)/\o033[93m\1\o033[39m/' file | less -R

Further reading:


If you want to pass the output to less you don't need a sed command at all, just set how less should highlight searched pattern (e.g. in .bashrc):

export LESS_TERMCAP_so=$'\e[93m'    # begin standout mode
export LESS_TERMCAP_se=$'\e[m'      # end standout mode

and then run less with -p option:

less -p '.*DATA.*' file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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