Unix Shell - blinking an AWK output

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > September 2006 > blinking an AWK output





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author blinking an AWK output
apogeusistemas@gmail.com

2006-09-18, 7:50 pm

Please, how can I make this awk command works fine ? (blinking output )
?

# echo $a

3.3G
# echo $a | awk '{ if (index($1, "G") > 0) { print `tput blink` $1
`tput sgr0` }'

Thanks.

Jon LaBadie

2006-09-18, 7:50 pm

apogeusistemas@gmail.com wrote:
> Please, how can I make this awk command works fine ? (blinking output )
> ?
>
> # echo $a
>
> 3.3G
> # echo $a | awk '{ if (index($1, "G") > 0) { print `tput blink` $1
> `tput sgr0` }'
>
> Thanks.
>


This isn't windows, don't work as the administrator.

awk -v blinkON=$(tput blink) -v blinkOFF=$(tput sgr0) '
index($1, "G") > 0) {
print blinkON $1 blinkOFF
}
'
apogeusistemas@gmail.com

2006-09-18, 7:50 pm


Jon LaBadie wrote:
> apogeusistemas@gmail.com wrote:
>
> This isn't windows, don't work as the administrator.
>
> awk -v blinkON=$(tput blink) -v blinkOFF=$(tput sgr0) '
> index($1, "G") > 0) {
> print blinkON $1 blinkOFF
> }
> '



Running command:

echo $a | /usr/xpg4/bin/awk -v blinkON=$(tput blink) -v blinkOFF=$(tput
sgr0) 'index($1, "G") > 0) { print blinkON $1 blinkOFF }'

show me this output:

/usr/xpg4/bin/awk: unbalanced E char Context is:[vbcol=seagreen]

apogeusistemas@gmail.com

2006-09-18, 7:50 pm


apogeusiste...@gmail.com wrote:[vbcol=seagreen]
> Jon LaBadie wrote:
>
>
> Running command:
>
> echo $a | /usr/xpg4/bin/awk -v blinkON=$(tput blink) -v blinkOFF=$(tput
> sgr0) 'index($1, "G") > 0) { print blinkON $1 blinkOFF }'
>
> show me this output:
>
> /usr/xpg4/bin/awk: unbalanced E char Context is:


/usr/xpg4/bin/awk: unbalanced E char Context is:
^[[5m^[[m^Oindex($1, "G") > 0)

Ed Morton

2006-09-18, 7:50 pm

apogeusistemas@gmail.com wrote:
> apogeusiste...@gmail.com wrote:
>
>
>
>
> /usr/xpg4/bin/awk: unbalanced E char Context is:
> ^[[5m^[[m^Oindex($1, "G") > 0)
>


Count the brackets. You don't need "> 0)".

Ed.
apogeusistemas@gmail.com

2006-09-19, 1:35 am


Ed Morton wrote:
> apogeusistemas@gmail.com wrote:
>
> Count the brackets. You don't need "> 0)".
>
> Ed.


Thanks folks !

Dan Mason

2006-09-20, 7:52 pm

apogeusistemas@gmail.com wrote:
> Please, how can I make this awk command works fine ? (blinking output )
> ?
>
> # echo $a
>
> 3.3G
> # echo $a | awk '{ if (index($1, "G") > 0) { print `tput blink` $1
> `tput sgr0` }'


You can skip the running the external program (tput) if you use these ascii
escape sequences.

\033[5m <- blink on
\033[m <- off

So you could replace your print statement with something more efficient,
like this.

print "\033[5m" $1 "\033[m"


Dan

--
| Daniel R Mason | "An ignorant people is |
| danmason@danmason.net | the blind instrument of |
| www.danmason.net | its own destruction." |
| Unix Systems Engineer | Simon Bolivar, Liberator |
Chris Mattern

2006-09-20, 7:52 pm

Dan Mason wrote:
> apogeusistemas@gmail.com wrote:
>
>
>
> You can skip the running the external program (tput) if you use these ascii
> escape sequences.
>
> \033[5m <- blink on
> \033[m <- off
>
> So you could replace your print statement with something more efficient,
> like this.
>
> print "\033[5m" $1 "\033[m"
>


That's great. If your terminal uses those escape codes. Not every
terminal does, you know. tput will use your $TERM to consult the
terminfo database and use the right escape codes, *whatever your
terminal happens to be* (provided that $TERM is set correctly and
the terminal is in terminfo, of course. The first should always
happen in a well-configured system, and terminfo has a very large
collection of terminal types to ensure it meets the second). You're
saving a couple of microseconds at the cost of destroying the program's
portability. Not a good trade, IMHO.


--
Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
Chris F.A. Johnson

2006-09-21, 1:25 pm

On 2006-09-20, Chris Mattern wrote:
> Dan Mason wrote:
>
> That's great. If your terminal uses those escape codes. Not every
> terminal does, you know. tput will use your $TERM to consult the
> terminfo database and use the right escape codes, *whatever your
> terminal happens to be* (provided that $TERM is set correctly and
> the terminal is in terminfo, of course. The first should always
> happen in a well-configured system, and terminfo has a very large
> collection of terminal types to ensure it meets the second). You're
> saving a couple of microseconds at the cost of destroying the program's
> portability. Not a good trade, IMHO.


Unfortunately, tput is no more portable than the escape codes. The
POSIX spec says that tput only needs to support the clear, init
and reset operands.

There are still systems in use which do not have tput, and there
are two different set of operands in use on different systems. A
tput command which works on a Linux system may not work on a
FreeBSD computer.

On the other hand, there *is* a standard for terminals, ISO-6429,
which is almost the same as the older ANSI x3.64, which is
basically VT100. The number of terminals which do not support the
standard is very small, and getting smaller.

By encapsulating screen codes in functions, they can easily be
replaced by those for a different terminal in the unlikely even
that it should be necessary.

In the OP's case, it should be noted that many terminals will not
blink and may use bold or beep when asked to blink.

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com