Thursday, May 22, 2008

Highlight a field using tput - awk


details.txt is a sample file whose last field has to be highlighted.


$ cat details.txt
Ramesh:India:IDERT23
Lenin:UK:ERT1276U
Maher:China:908TYU
Lue:Bhutan:V567UY


Required Output:


Click the picture to get a enlarge view

awk code

$ awk -v B=`tput smso` -v N=`tput rmso` '
BEGIN { FS=OFS=":" }
$NF= B $NF N {print}' details.txt


The screen shot:















Click the picture to get a enlarge view

tput smso/rmso : enables and disables standout mode for a text screen session


$ bold=`tput smso`;offbold=`tput rmso`
$ echo "BASH ${bold}SCRIPTING${offbold}"


The above will print the word SCRIPTING as highlighted.

Same like above:

$ echo "BASH `tput smso`SCRIPTING `tput rmso`"

No comments:

© Jadu Saikia www.UNIXCL.com