[HPADM] RE: Awk and $PATH

From: Shaw, Matthew (Matt.Shaw@xwave.com)
Date: Thu Jan 29 2004 - 15:03:05 EST


Stuart:
 
The $0 variable in awk is only 'recomputed' when an operation is
performed on the data in question. So no matter what you set the OFS to,
$0 will not be recomputed until you actually do 'something' to the
fields. One way to force a recomputation is to insert a command that
performs an operation on the fields while not modifying them:
 
echo $PATH | awk -F: '{OFS="\n"; $1=$1; print $0;}'
 
This will force the $0 to be updated properly with the correct OFS. This
has always seemed a little backwards to me, so I decided to do some
checking with google. Despite it's clunkiness, this appears to be the
'supported method'.
 
You can recreate the same behaviour in a somewhat more straightforward
manner with sed however: (the use of 'straightforward' here is also
questionable :)
 
echo $PATH | sed 's/:/\
/g'
 
(That's an actual 'Enter' after 's/:/\' - you can't insert a newline
with a character, you have to actually escape (\) a 'real' newline)
 
Hope this helps.
 
Thanks
 
Matt Shaw
Technical Architect
xwave, An Aliant Company
Desk: 506-389-4641
Cell: 506-863-8949
matt.shaw@xwave.com
 
 
-----Original Message-----
From: hpux-admin-owner@DutchWorks.nl
[mailto:hpux-admin-owner@DutchWorks.nl] On Behalf Of
SAbramson@Wabtec.com
Sent: Thursday, January 29, 2004 3:11 PM
To: hpux-admin@DutchWorks.nl
Subject: [HPADM] Awk and $PATH
 
Can someone tell me why:
        if this works:
                # echo $PATH | awk -F: '{print $1}'
                        /usr/sbin/
        why does't this work:
                # echo $PATH | awk -F: '{OFS="\n";print $0}'
 
/usr/sbin/:/usr/bin/:/usr/sbin:/usr/bin:/opt/ansic/bin:/usr/ccs/bin:/usr
/contrib/bin:/opt/fc/bin:/opt/fcms/bin:/opt/nettladm/bin:/opt/upgrade/bi
n:/opt/pd/bin:/usr/bin/X11:/usr/contrib/bin/X11:/opt/resmon/bin:/opt/pre
d/bin:/opt/hparray/bin:/opt/perf/bin:/opt/ignite/bin:/opt/cxperf/bin:/op
t/langtools/bin:/opt/imake/bin://opt/perl/bin:/opt/aCC/bin:/opt/hpnp//bi
n:/opt/networker/bin:/opt/graphics/common/bin:/opt/samba-2.2.5/source/bi
n:/sbin:/home/root:/usr/emc/ECC/bin:/usr/symcli/bin:/usr/symmapps/vcm:/u
sr/local/bin:/home/saroot/bin:/opt/perf/bin:/usr/symcli/bin:/usr/symcli6
4/bin/
 
What I want to do, is separate each separate directory in $PATH on it's
own line.
        Stuart
Stuart Abramson | WABTEC Corp. | Wilmerding, PA
Off: 412/825-1434 | Cell: 412/417-1567 | email:
sabramson@wabtec.com

***** CONFIDENTIALITY NOTE *****
The content contained in this e-mail transmission is legally privileged
and confidential information intended only for the use of the individual
or entity named herein. If the reader of this transmission is not the
intended recipient, you are hereby notified that any dissemination,
distribution, or copying of this transmission is strictly prohibited.

--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact majordomo@dutchworks.nl
       Name: hpux-admin@dutchworks.nl     Owner: owner-hpux-admin@dutchworks.nl
 
 Archives:  ftp.dutchworks.nl:/pub/digests/hpux-admin       (FTP, browse only)
            http://www.dutchworks.nl/htbin/hpsysadmin   (Web, browse & search)


This archive was generated by hypermail 2.1.7 : Sat Apr 12 2008 - 11:02:38 EDT