Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

colore email adress

Status
Not open for further replies.

w5000

Technical User
Nov 24, 2010
223
0
0
PL
hi,
I'd like to have colored the first occurrence of an email address xxxx@xxxx.xxx.xxx in each matched line

I tried with gnu grep like this:
grep --color -P "[[:space:]]+[[:alpha:]]+@[[:alnum:]]+.+[[:space:]]" input
but it shows all in color to the end of line.

I found another way with tput:
# on=$(tput setaf 7; tput setab 1; tput bold) off=$(tput sgr0)
# sed "s/[^[:blank:]]\{1,\}/$on&$off/10" input

it is coloring column 10, but can the sed be learned to color first column matching the 'e-mail' pattern?
 
ok, I've found a solution with grep:

grep --colour -E "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b" input
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top