[SunHELP] stty erase
Ledger, David
sunhelp at sunhelp.org
Fri Mar 30 08:23:50 CST 2001
Brian wrote
>>> TTY=`tty | cut -c 6-`
>>> who | grep $TTY | awk 'BEGIN { FS="(" } {print $2}' | cut -d . -f 1
>>
>> who|grep $TTY |awk -F "(" '{print$2}"| cut -d . -f 1
>i was thinking more along the lines of:
>let's examine my original "script". there are two calls to 'cut', one to
>'grep', one to 'awk', one to 'tty' and one to 'who'.
>now, we can't really avoid the calls to tty and who, but do we really need
to
>call four other programs to do this when we are already calling awk which
is an
>extensively powerful tool. so i guess what i was saying by "cleaning up"
was
>to remove those extra calls as much as possible. would it be possible to
write
>the entire thing in awk? i would assume the answer is yes, and if i had
an awk
>book handy i'd figure it out.
That's how I feel every time I see greps, seds, awks cuts etc in the same
pipeline.
There are cases where you need to, but they are rare.
TTY=$(tty)
who | awk -F'[ ()\.]+' '$2 == "'"${TTY#/dev/}"'"{print $6}'
will do it (those quote sequences are double single double for those with
non-fixed fonts).
Or a bit less cryptic:
TTY=$(tty)
who | awk '$2 == tty {
gsub(/[()]/,"",$6)
split($6, a, ".")
print a[1]
} ' tty=${TTY#/dev/}
which can be put on one line with ';'s where needed.
David
This is my opinion only, and not that of my employer who is ... me ..
Unless the contents indicate otherwise, it has no connection with my current
client whose email services I am using.
David Ledger - Freelance Unix SysAdmin & chair of HP/Works SysAdmin SIG
dledger at ivdcs.demon.co.uk - becoming dledger at ivdcs.co.uk
www.ivdcs.demon.co.uk - becoming www.ivdcs.co.uk
=====================================================================
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
gpupower.co.uk or postmaster at npower.com
This outgoing e-mail (and any attachments) has been checked
(using Sophos Sweep 3.43 + patches) before leaving us (UK 08457 353637),
and has been found to be clean from any virus infection.
=====================================================================
More information about the SunHELP
mailing list