Preserve ls colouring after grep’ing

Your grep is probably removing ls‘s color codes because it has its own coloring turned on. You “could” do this: ls -l –color=always | grep –color=never pattern However, it is very important that you understand what exactly you’re grepping here. Not only is grepping ls unnecessary (use a glob instead), this particular case is grepping … Read more

Colorize tail output

yes, there is way to do this. That is, as long as your terminal supports ANSI escape sequences. This is most terminals that exist. I think I don’t need explain how to grep, sed etc. point is the color right? see below, this will make WARN yellow ERROR red foo green here is example: kent$ … Read more

Percent sign % not working in crontab

% is a special character for crontab. From man 5 crontab: The “sixth” field (the rest of the line) specifies the command to be run. The entire command portion of the line, up to a newline or a “%” character, will be executed by /bin/sh or by the shell specified in the SHELL variable of … Read more

Remove substring matching pattern both in the beginning and the end of the variable

Well, you can’t nest ${var%}/${var#} operations, so you’ll have to use temporary variable. Like here: var=”http://whatever/score/” temp_var=”${var#http://}” echo “${temp_var%/score/}” Alternatively, you can use regular expressions with (for example) sed: some_variable=”$( echo “$var” | sed -e ‘s#^http://##; s#/score/$##’ )”