Unix/Linux Forum: Awk Scripting - Unix/Linux Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Awk Scripting Need help with an AWK Script Rate Topic: -----

#1 User is offline   Cipher786 

  • Newbie (User Level: 0/10)
  • Group: Members
  • Posts: 2
  • Joined: 21-July 09

Posted 21 July 2009 - 05:51 PM

Hi, All -

awk5.awk contains the following script:

BEGIN {
	printf "The following are directory files:"
	"ls -l | grep '^d' | {print $0}"
	printf "There were "NR" directories in this list."
      }


When I run the script, Here is what I get:
clyde% awk -f awk5.awk
The following are directory files:There were 0 directories in this list.clyde%

When I run "ls -l | grep '^d'" by itself, I get 20 directories. How can I correct the script.

Thanks in advance...
0

#2 User is offline   Cipher786 

  • Newbie (User Level: 0/10)
  • Group: Members
  • Posts: 2
  • Joined: 21-July 09

Posted 21 July 2009 - 09:56 PM

Thanks for taking a look at this question. Here is how I resolved it:

BEGIN	{
  		printf "The following are directory files:\n"
  		while(("ls -l|grep '^d'"|getline ) > 0){print;i++}
  		print "There were "i" directories in this list."
	}

0

#3 User is offline   edidataguy 

  • Newbie (User Level: 0/10)
  • Group: Members
  • Posts: 7
  • Joined: 21-July 09

Posted 23 July 2009 - 03:15 AM

View PostCipher786, on 21 July 2009 - 03:56 PM, said:

Thanks for taking a look at this question. Here is how I resolved it:

BEGIN	{
  		printf "The following are directory files:\n"
  		while(("ls -l|grep '^d'"|getline ) > 0){print;i++}
  		print "There were "i" directories in this list."
	}



Must it be in AWK only?
If not, this will work:
ls -l|grep '^d'| wc -l

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users