Code Comments
Programming Forum and web based access to our favorite programming groups.
warezcrc@hotmail.com wrote:
> make it look like this ex.
>
> ls -Fl | awk '{print "\t"$3, $4, "'"$PWD"'/"$9}' | sed 1d
>
> and you get what you want i believe, had the same problem what you are
> looking for in this ex. is this part '"$PWD"' that will get you your
> variable, replace $PWD with yours.
>
I didn't see the original posting for this response, but that's the
worst possible way to use shell variables with awk (read the
comp.lang.awk and comp.unix.shell FAQs), and you don't need the sed.
Do this:
ls -Fl |awk -vpwd="$PWD" 'NR>1{printf "\t%s %s %s/%s\n",$3,$4,pwd,$9}'
If your awk doesn't support -v, use the ENVIRON array or set the
variable at the end of the line (again see the FAQs).
Ed.
Post Follow-up to this messageIn article <n5-dncs_aujYRl_cRVn-rA@comcast.com>,
Ed Morton <morton@lsupcaemnt.com> wrote:
>Do this:
>
>ls -Fl |awk -vpwd="$PWD" 'NR>1{printf "\t%s %s %s/%s\n",$3,$4,pwd,$9}'
>
>If your awk doesn't support -v, use the ENVIRON array or set the
>variable at the end of the line (again see the FAQs).
Any awk that doesn't support -v won't have ENVIRON in it
either. In which case, you can use
ls -Fl | gawk '.....' pwd=$PWD -
Arnold
--
Aharon (Arnold) Robbins --- Pioneer Consulting Ltd. arnold AT skeeve DOT com
P.O. Box 354 Home Phone: +972 8 979-0381 Fax: +1 206 350 8765
Nof Ayalon Cell Phone: +972 50 729-7545
D.N. Shimshon 99785 ISRAEL
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.