![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
|||
|
|||
|
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
|
|||
|
|||
|
thanks tommy,
but what i need is the total wc for all executables, not just how many there are |
|
#4
|
|||
|
|||
|
Quote:
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
|
|||
|
|||
|
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
|
||||
|
||||
|
Quote:
ls -F | grep '*' | wc -w |
|
#7
|
||||
|
||||
|
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 |