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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to underline a text

Status
Not open for further replies.

cantubas

Programmer
Jan 8, 2004
45
FR
i wants to seach text and when i underline it in the same file.

i try with tr and with sed but i can't do it

it is possible?
 
What kind of undurline do you want ?

For printing ? TEXT\b\b\b\b____
For displaying on screen ? \033[4mTEXT\033[0m
Other type ?



Jean Pierre.
 
on screen but on terminal HP.

that why i try with the function tput but sed and tr don't accept a funtion into a string.
 
Try..
[tt]
STRING='search text'
FILENAME='yourfile.txt'
SU=`tput smul`
EU=`tput rmul`
sed -n "s/\($STRING\)/$SU\1$EU/p" $FILENAME
 
Solution 1 using sed :
[tt]
--- underline.sh ---
[ $# -eq 0 ] && exit
SedFile=/tmp/underline.sed.$$
Text="$1"
shift

cat <<EOF >$SedFile
s/\($Text\)/$(tput sgr 0 1)\1$(tput sgr 0 0)/g
EOF

sed -f $SedFile $*
rm -f $SedFile
--------------------

underline.sh searched_text [ files... ]
[/tt][/i]

Solution 2 using awk :
[tt]
--- underline.awk ---
BEGIN {
if (ARGC < 2) exit;
&quot;tput sgr 0 1&quot; | getline Under_On ;
&quot;tput sgr 0 0&quot; | getline Under_Off ;
Text = ARGV[1] ;
ARGV[1] = &quot;&quot;;
if (ARGC == 2) ARGV[ARGC++] = &quot;-&quot;;
Underlined = Under_On Text Under_Off;
}
{
gsub(Text,Underlined);
print $0;
}

---------------------

awk -f underline.awk searched_text [ files... ]
[/tt]




Jean Pierre.
 
Try something like this:
Code:
smul=`tput smul`; sgr0=`tput sgr0`
str=&quot;YourSearchedString&quot;
awk '{gsub(/'&quot;$str&quot;'/,&quot;'&quot;${smul}${str}${sgr0}&quot;'&quot;);print
}' /path/to/file


Hope This Help
PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top