Rick Welykochy wrote:
Try this:
dirs -v | perl -wnla -e 'BEGIN {$\=" "; $,=":"} print @F;'; echo
That works perfectly, but not quite for the reasons you explained.
$\ is Perl's Output Record Separator, and is printed at the end of every print
statement. $/ is Perl's Input Record Separator. When using -a (autosplit) we
split on spaces by default. -l enables automatic end of line processing (ie it
changes $\). Thus:
dirs -v | perl -wnla -e 'print @F;'
yields:
0/etc
1/tmp
2/home/jarich
(including the final newline).
$, is Perl's Output Field Separator as you expected. The begin block isn't
necessary so we can write:
dirs -v | perl -wnla -e '$,=":"; print @F;'
to get the desired:
0:/etc
1:/tmp
2:/home/jarich
Since we're using -l anyway, we could use it to set $\ for us:
dirs -v | perl -wna -l040 -e '$,=":"; print @F;'
0:/etc 1:/tmp 2:/home/jarich
or we can do it ourselves:
dirs -v | perl -wna -e '$,=":"; $\=" "; print @F;'
All the best,
Jacinta
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html