Unix Helpers

From Blue-IT.org Wiki

Revision as of 10:33, 7 January 2014 by Apos (talk | contribs) (Created page with "== grep == === Colored output === Colered Output of a complete file. The regular expression "|$" matches those line that matches the pattern AND have an endline. This are ALL...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

grep

Colored output

Colered Output of a complete file. The regular expression "|$" matches those line that matches the pattern AND have an endline. This are ALL lines of the file!

egrep --color "pattern|$" file
grep --color -E "pattern|$" file
#!/bin/bash

regex="${1}"

# 1 green
# 3 red 
highlight_on=$(tput setaf 2) # green, use setab to do inverse instead of foreground
highlight_off=$(tput sgr0)

while read line
do
    $line =~ $regex  && echo -n $"$highlight_on"
    echo "$line$highlight_off"
done