For Programmers: Free Programming Magazines  


Home > Archive > AWK > December 2004 > Re: Passing string to awk









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Passing string to awk
Ed Morton

2004-12-17, 3:56 pm



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.
Aharon Robbins

2004-12-18, 8:55 pm

In 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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com