You are not logged in.

#1 2008-07-08 09:48:18

fluorite
Member
Registered: 2006-08-27
Posts: 33

tool for highlighting a pattern in terminal

I'm looknig for a tool which can be used in terminal for highlighting patterns. For example

$ cat fruits
banana
apple
orange

$ cat fruits | hilight_magic_tool apple
banana
apple # <-- highlightetd
orange

$ cat fruits | hilight_magic_tool strawberry
banana
apple
orange

Its quite similiar to grep --color=auto but grep shows only output when the pattern occurs, when the pattern doesn't occur it acts like simple cat.

Anybody knows the real name of the hilight_magic_tool?


If a man does not know to what port he is sailing, no wind is favourable
- Seneca

Offline

#2 2008-07-08 11:14:03

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: tool for highlighting a pattern in terminal

Make a sed script:

#!/bin/dash
sed -e 's/'"$1"'/^[[31m&^[[m/g'

The ^[[ is made by CTRL+v, ESC, [

EDIT: added double quotes around $1 to make more possible.

Last edited by Procyon (2008-07-08 11:19:26)

Offline

#3 2008-07-08 11:35:56

fluorite
Member
Registered: 2006-08-27
Posts: 33

Re: tool for highlighting a pattern in terminal

Great cool It works perfectly!!! Thanks a lot!!!

Stupid me, forget about sed tongue


If a man does not know to what port he is sailing, no wind is favourable
- Seneca

Offline

#4 2008-07-08 14:51:12

carlocci
Member
From: Padova - Italy
Registered: 2008-02-12
Posts: 368

Re: tool for highlighting a pattern in terminal

grep --color=auto

Offline

#5 2008-07-10 05:26:55

bsdson.tw
Member
From: Taiwan
Registered: 2005-05-06
Posts: 161

Re: tool for highlighting a pattern in terminal

use "less" and search inside it.

Offline

Board footer

Powered by FluxBB