SI
SI
discoversearch

We've detected that you're using an ad content blocking browser plug-in or feature. Ads provide a critical source of revenue to the continued operation of Silicon Investor.  We ask that you disable ad blocking while on Silicon Investor in the best interests of our community.  If you are not using an ad blocker but are still receiving this message, make sure your browser's tracking protection is set to the 'standard' level.
Politics : Formerly About Advanced Micro Devices -- Ignore unavailable to you. Want to Upgrade?


To: d[-_-]b who wrote (1022341)6/23/2017 1:55:47 PM
From: Thomas A Watson  Read Replies (2) | Respond to of 1573096
 
well bash is lousy for any unix except linux. I've used tcsh on a dozen or more of commercial unixes. On the other hand other unixes are getting more and more rare.

As to functions. In the beginning there was no bash, csh sh and tcsh and ksh. So to work on several unixes one chose a common compatible.

you call a script from a script and pipe from script to script.

I've found over and over I need to extract one column from several in a record.

This was a simple utility function.
watson@xen2[2328]cat /usr/local/bin/P1
#!/bin/tcsh
# /hda4/home/watson/bin/P1
# Copyright Tom Watson (C) 2003 watman.com
# Licensed under the Open Software License version 1.1
# License Text at opensource.org
# Developed on Red Hat Linux release 7.3 (Valhalla)
# rpm tcsh-6.10-6 gawk-3.1.0-4

# extracts column 1 to 10 as P1 to P10
# pipe output of text into Pn

# setup up softlinks first time only.

if ( !( -e /usr/local/bin/P2) ) then
ln -s /usr/local/bin/P1 /usr/local/bin/P2
endif
if ( !( -e /usr/local/bin/P3) ) then
ln -s /usr/local/bin/P1 /usr/local/bin/P3
endif
if ( !( -e /usr/local/bin/P4) ) then
ln -s /usr/local/bin/P1 /usr/local/bin/P4
endif
if ( !( -e /usr/local/bin/P5) ) then
ln -s /usr/local/bin/P1 /usr/local/bin/P5
endif
if ( !( -e /usr/local/bin/P6) ) then
ln -s /usr/local/bin/P1 /usr/local/bin/P6
endif
if ( !( -e /usr/local/bin/P7) ) then
ln -s /usr/local/bin/P1 /usr/local/bin/P7
endif
if ( !( -e /usr/local/bin/P8) ) then
ln -s /usr/local/bin/P1 /usr/local/bin/P8
endif
if ( !( -e /usr/local/bin/P9) ) then
ln -s /usr/local/bin/P1 /usr/local/bin/P9
endif
if ( !( -e /usr/local/bin/P10) ) then
ln -s /usr/local/bin/P1 /usr/local/bin/P10
endif
if ( !( -e /usr/local/bin/PLAST) ) then
ln -s /usr/local/bin/P1 /usr/local/bin/PLAST
endif
rehash
# arg 0 is the name of command.
set command=`echo $0 | awk -F/ '{print $NF}' `

if ( $command == P1 ) then
if ( $1 == "" ) then
awk '{print $1}'
else
awk -F$1 '{print $1}'
endif
exit
endif

if ( $command == P2 ) then
if ( $1 == "" ) then
awk '{print $2}'
else
awk -F$1 '{print $2}'
endif
exit
endif

if ( $command == P3 ) then
if ( $1 == "" ) then
awk '{print $3}'
else
awk -F$1 '{print $3}'
endif
exit
endif

if ( $command == P4 ) then
if ( $1 == "" ) then
awk '{print $4}'
else
awk -F$1 '{print $4}'
endif
exit
endif

if ( $command == P5 ) then
if ( $1 == "" ) then
awk '{print $5}'
else
awk -F$1 '{print $5}'
endif
exit
endif

if ( $command == P6 ) then
if ( $1 == "" ) then
awk '{print $6}'
else
awk -F$1 '{print $6}'
endif
exit
endif

if ( $command == P7 ) then
if ( $1 == "" ) then
awk '{print $7}'
else
awk -F$1 '{print $7}'
endif
exit
endif

if ( $command == P8 ) then
if ( $1 == "" ) then
awk '{print $8}'
else
awk -F$1 '{print $8}'
endif
exitwatson@xen2[2328]cat /usr/local/bin/P1
#!/bin/tcsh
# /hda4/home/watson/bin/P1
# Copyright Tom Watson (C) 2003 watman.com
# Licensed under the Open Software License version 1.1
# License Text at opensource.org
# Developed on Red Hat Linux release 7.3 (Valhalla)
# rpm tcsh-6.10-6 gawk-3.1.0-4

# extracts column 1 to 10 as P1 to P10
# pipe output of text into Pn

# setup up softlinks first time only.

if ( !( -e /usr/local/bin/P2) ) then
ln -s /usr/local/bin/P1 /usr/local/bin/P2
endif
if ( !( -e /usr/local/bin/P3) ) then
ln -s /usr/local/bin/P1 /usr/local/bin/P3
endif
if ( !( -e /usr/local/bin/P4) ) then
ln -s /usr/local/bin/P1 /usr/local/bin/P4
endif
if ( !( -e /usr/local/bin/P5) ) then
ln -s /usr/local/bin/P1 /usr/local/bin/P5
endif
if ( !( -e /usr/local/bin/P6) ) then
ln -s /usr/local/bin/P1 /usr/local/bin/P6
endif
if ( !( -e /usr/local/bin/P7) ) then
ln -s /usr/local/bin/P1 /usr/local/bin/P7
endif
if ( !( -e /usr/local/bin/P8) ) then
ln -s /usr/local/bin/P1 /usr/local/bin/P8
endif
if ( !( -e /usr/local/bin/P9) ) then
ln -s /usr/local/bin/P1 /usr/local/bin/P9
endif
if ( !( -e /usr/local/bin/P10) ) then
ln -s /usr/local/bin/P1 /usr/local/bin/P10
endif
if ( !( -e /usr/local/bin/PLAST) ) then
ln -s /usr/local/bin/P1 /usr/local/bin/PLAST
endif
rehash
# arg 0 is the name of command.
set command=`echo $0 | awk -F/ '{print $NF}' `

if ( $command == P1 ) then
if ( $1 == "" ) then
awk '{print $1}'
else
awk -F$1 '{print $1}'
endif
exit
endif

if ( $command == P2 ) then
if ( $1 == "" ) then
awk '{print $2}'
else
awk -F$1 '{print $2}'
endif
exit
endif

if ( $command == P3 ) then
if ( $1 == "" ) then
awk '{print $3}'
else
awk -F$1 '{print $3}'
endif
exit
endif

if ( $command == P4 ) then
if ( $1 == "" ) then
awk '{print $4}'
else
awk -F$1 '{print $4}'
endif
exit
endif

if ( $command == P5 ) then
if ( $1 == "" ) then
awk '{print $5}'
else
awk -F$1 '{print $5}'
endif
exit
endif

if ( $command == P6 ) then
if ( $1 == "" ) then
awk '{print $6}'
else
awk -F$1 '{print $6}'
endif
exit
endif

if ( $command == P7 ) then
if ( $1 == "" ) then
awk '{print $7}'
else
awk -F$1 '{print $7}'
endif
exit
endif

if ( $command == P8 ) then
if ( $1 == "" ) then
awk '{print $8}'
else
awk -F$1 '{print $8}'
endif
exit
endif

if ( $command == P9 ) then
if ( $1 == "" ) then
awk '{print $9}'
else
awk -F$1 '{print $9}'
endif
exit
endif

if ( $command == P10 ) then
if ( $1 == "" ) then
awk '{print $10}'
else
awk -F$1 '{print $10}'
endif
exit
endif

#NOTE to pass / as $1 \\\/
if ( $command == PLAST ) then
if ( $1 == "" ) then
awk '{print $NF}'
else
awk -F$1 '{print $NF}'
endif
exit
endif

#other awk syntax awk -F/ '{print $(NF-1)"/"$NF }'
endif

if ( $command == P9 ) then
if ( $1 == "" ) then
awk '{print $9}'
else
awk -F$1 '{print $9}'
endif
exit
endif

if ( $command == P10 ) then
if ( $1 == "" ) then
awk '{print $10}'
else
awk -F$1 '{print $10}'
endif
exit
endif

#NOTE to pass / as $1 \\\/
if ( $command == PLAST ) then
if ( $1 == "" ) then
awk '{print $NF}'
else
awk -F$1 '{print $NF}'
endif
exit
endif

#other awk syntax awk -F/ '{print $(NF-1)"/"$NF }'