Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: Passing string to awk

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.

Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
12-17-04 08:56 PM


Re: Passing string to awk
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

Report this thread to moderator Post Follow-up to this message
Old Post
Aharon Robbins
12-19-04 01:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:35 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.