Gawk adding color


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Gawk adding color
# 1  
Old 12-21-2012
Gawk adding color

I want to know if there is any way to highlight search results using GAWK. So for example:

Code:
gawk '{IGNORECASE=1;} /^<a/&&/\$/' index.html
<a class=author href="http://washingtondc.craigslist.org/search/?areaID=10&amp;amp;catAbb=sss&amp;amp;query=ps vita" title="craigslist washington, DC | all for sale / wanted search &quot;ps vita&quot;">Craigslist Half Hourly Vista</a> <a href="http://washingtondc.craigslist.org/nva/msg/3486749195.html" lang="en-us">Traveler Guitar (Fairfax) $250</a><div class="content">discount price online - is $380

My search results are not highlighted like using grep. Any ideas

Last edited by metallica1973; 12-21-2012 at 12:40 PM..
# 2  
Old 12-21-2012
Try this:-
Code:
gawk '{IGNORECASE=1;} /^<a/&&/\$/ { print "\033[1;31m:" $0 "\033[0m" }' index.html

# 3  
Old 12-21-2012
awesome,

but it highlights everything red. Is there a way that it will just highlight my search criteria like grep?
# 4  
Old 12-21-2012
You can specify which parameter or search criteria you want to highlight, here is an example:-
Code:
echo "red green yellow blue magenta cyan white" | awk ' {
 print "\033[1;31m" $1 "\033[0m";
 print "\033[1;32m" $2 "\033[0m";
 print "\033[1;33m" $3 "\033[0m";
 print "\033[1;34m" $4 "\033[0m";
 print "\033[1;35m" $5 "\033[0m";
 print "\033[1;36m" $6 "\033[0m";
 print "\033[1;37m" $7 "\033[0m";
} '

Login or Register to Ask a Question

Previous Thread | Next Thread

3 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Adding Color using More

Daily Stupid Question: When I use a cat with a grep I can see "blind SQL injection vulnerablity" highlighted as red and is easily readable cat file |grep -i 'blind\ SQL\ injection\ vulnerability' When I add a more to view the results page at a time, the color is taken away and is... (3 Replies)
Discussion started by: metallica1973
3 Replies

2. UNIX for Dummies Questions & Answers

How to change the background color in the init 3 mode(not line color)

Hello, I am using RHEL 6.1 on VMware I am searching for a way to change background color (not line by line color wich one can using tput command) basically changing the color of the whole screen to white instead of the default black and changing font color to black and alos would like to... (2 Replies)
Discussion started by: Dexobox
2 Replies

3. OS X (Apple)

Adding Color to bash

Hey everyone, I have come across an issue to where I am trying to create a script which changes the text color with a simple if then statement. I have seen it done with Fedora 8 but when I try and create it using my MacBook Pro running Snow Leopard it doesn't work. Funny thing is, when I use... (2 Replies)
Discussion started by: dachadster13
2 Replies
Login or Register to Ask a Question