The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help Required: Command to find IP address and command executed of a user loggedout Security 2 08-06-2008 05:12 PM
how to? launch command with string of command line options TinCanFury Shell Programming and Scripting 5 04-28-2008 03:06 PM
inconsistent ls command display at the command prompt & running as a cron job rajranibl Linux 5 07-30-2007 05:26 AM
How to use more than one MPE command STREAM with Unix command in a single shell? bosskr HP-UX 1 10-16-2006 01:16 PM
How to use more than one MPE command STREAM with Unix command in a single shell? bosskr Shell Programming and Scripting 0 09-19-2006 06:44 PM

Closed Thread
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-04-2003
Registered User
 

Join Date: Sep 2003
Posts: 5
Awk command

Hey guys,
need help writing a script which will display the total word count of all executables in the current directory. I believe awk is necessary but im unfamiliar with the command could someone please explain it to me or how it would apply to this script? as of now i have it printing the filenames and the wc for each executable but cant get the total.
Forum Sponsor
  #2  
Old 11-04-2003
Registered User
 

Join Date: Nov 2003
Location: Finland
Posts: 31
Can't imagine real life usage for this, but here it comes:

> ls -l | grep -c "^-.*x "

This will show how many executable (owner, group or other having x-bit set) files are located in your working directory.

---Tommy
  #3  
Old 11-04-2003
Registered User
 

Join Date: Sep 2003
Posts: 5
thanks tommy,
but what i need is the total wc for all executables, not just how many there are
  #4  
Old 11-04-2003
flim flam flamma jamma
 

Join Date: May 2001
Location: Chicago IL, USA
Posts: 1,006
Quote:
Originally posted by Aesop
thanks tommy,
but what i need is the total wc for all executables, not just how many there are
all unix commands are only going to be 1 word.

I guess you would have to define word count.

why dont you post what you have of your script so far so we can see exactly what your talking about.

something tells me you can do what you are trying to do w/ the find command. useing the -perm argument. i just havent figured it out yet.

the only thing i can come up w/ useing the find command is:

Code:
$ ls -l
total 0
---x--x--x   1 joe     black          0 Nov  4 21:58 file0
---x------   1 joe     black          0 Nov  4 21:57 file1
------x---   1 joe     black          0 Nov  4 21:57 file2
---------x   1 joe     black          0 Nov  4 21:58 file3
$ find . -perm -u+x
.
./file1
./file0
$

Last edited by Optimus_P; 11-04-2003 at 03:17 PM.
  #5  
Old 11-04-2003
Registered User
 

Join Date: Sep 2003
Posts: 5
my script changes form like every 20 min,
i was thinking along the lines of using awk to search for any files with '*' denoting an executable, and getting $2 from it, then somehow adding those values.
  #6  
Old 11-04-2003
oombera's Avatar
Registered User
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
Quote:
Originally posted by Aesop
Hey guys,
need help writing a script which will display the total word count of all executables in the current directory.
Assuming they're all in one directory (and not subdirectories), would this work for you? This has to be close to what you have (as of the first post), but it gives you the total word count...

ls -F | grep '*' | wc -w
  #7  
Old 11-04-2003
TioTony's Avatar
Bit Pusher
 

Join Date: Oct 2001
Location: Southern California
Posts: 332
Is this more what you are looking for (at least the awk portion of it):

awk '{sum += $2} END {print sum}'

I am not sure what you were refering to with respect to $2, but assuming ls with some options give you the $2 you are looking for you could do this:


ls -F | grep "*" | awk '{sum += $2} END {print sum}'

This will print the total of all the values in the second column of your output. ls -F doesn't make sense on my systems but maybe it does on yours. What OS are you using?

Are you actually looking for word count of executibles or total size of the executibles? Word size as most people on this forum are thinking doesn't make sense since the binary is not made of ASCII words for the most part. If you are thinking of machine words (8 bits or such), then use this script. Same as above but divides by 8 before giving you the total. You may have to do more math if the second column of your output isn't bits, maybe it's blocks or kb:

ls -F | grep "*" | awk '{sum += $2} END {total = sum / 8; print total}'

You may also want to look at the "strings" command if you truely want to find the amount of ASCII text in the binary, but again I don't know if that makes any sense or not.
Google The UNIX and Linux Forums
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 08:36 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0