[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

find and file info

Posted on 2006-04-20
9
Medium Priority
?
290 Views
Last Modified: 2010-04-21
This first command returns file information, and the second returns all the directories with that filename, so
how would i put these together and execute the command in one.

wc -l -c INPUTFILE_FF | awk '{l=length();if(max < l){max=l};i++}END{print "Num. of lines:\t"i"\nLongest line:\t"l"\nEst. Filesize:\t"i*l"\n"}' INPUTFILE_FF


find /usr/dstage/data/Basel2/work -name "INPUTFILE_FF" -exec ls -la {} \; | more
0
Comment
Question by:mmatharu
7 Comments
 
LVL 51

Accepted Solution

by:
ahoffmann earned 500 total points
ID: 16499223
write following script (3 lines) and name it your-script.sh:

#!/bin/sh
wc -l -c $1 | awk '{l=length();if(max < l){max=l};i++}END{print "Num. of lines:\t"i"\nLongest line:\t"l"\nEst. Filesize:\t"i*l"\n"}'
ls -la $1

chmod 555 your-script.sh
find /usr/dstage/data/Basel2/work -name "INPUTFILE_FF" -exec /full/path/to/your-script.sh {} \;
0
 
LVL 7

Expert Comment

by:XoF
ID: 16505623
find /usr/dstage/data/Basel2/work -name "INPUTFILE_FF" -print | while read line;do wc -l -c $line | awk '{l=length();if(max < l){max=l};i++}END{print "File info:\n'`ls -la $line`'\nNum. of lines:\t"i"\nLongest line:\t"l"\nEst. Filesize:\t"i*l"\n"}';done

HTH,
-XoF-
0
 
LVL 3

Expert Comment

by:root_start
ID: 16650372
Hi mmatharu,

You can do this in two ways:

1. The one XoF suggested:
===============================================================
find /usr/dstage/data/Basel2/work -name "INPUTFILE_FF" -print 2>> /dev/null | while read line
do
  wc -l -c $line | awk '{l=length();if(max < l){max=l};i++}END{print "File info:\n'`ls -la $line`'\nNum. of lines:\t"i"\nLongest line:\t"l"\nEst.  Filesize:\t"i*l"\n"}'
done
===============================================================

Or you can use "for":
===============================================================
for file in `find /usr/dstage/data/Basel2/work -name "INPUTFILE_FF" -print 2>> /dev/null`
do
  wc -l -c $file | awk '{l=length();if(max < l){max=l};i++}END{print "File info:\n'`ls -la $file`'\nNum. of lines:\t"i"\nLongest line:\t"l"\nEst.  Filesize:\t"i*l"\n"}'
done
===============================================================

Also, do not forget to redirect the standard error output to "/dev/null", otherwise you can have an error an it will be reported during your script execution:
===============================================================
find /usr/dstage/data/Basel2/work -name "INPUTFILE_FF" -print 2>> /dev/null
===============================================================

I hope it helps.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:XoF
ID: 16672818
> for file in `find /usr/dstage/data/Basel2/work -name "INPUTFILE_FF" -print 2>> /dev/null`

Not the best idea, since some OS'es have pretty small buffers used for command arguments. If the find construct above returns several thousands of results, you _might_ encounter a buffer overflow, so that the loop itself won't be processed.

Regards,
-XoF-
0
 
LVL 6

Expert Comment

by:JJSmith
ID: 16881446

I would guess that the number of INPUTFILE_FF's found under /usr/dstage/data/Basel2/work would not blow the buffer. But from a more robust point of view I would endorse XoF comment that a find piped to a while read is much more 'economical' than a for in `find list` and therefore offers more future scalability.

Cheers
JJ

0
 
LVL 62

Expert Comment

by:gheist
ID: 16928751
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.
I will leave the following recommendation for this question in the Cleanup topic area:

split between ahoffmann http:#16499223 and root_start http:#16650372

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

gheist
EE Cleanup Volunteer
0
 
LVL 7

Expert Comment

by:XoF
ID: 16930453
hmm, just wondering why you suggest splitting between ahoffmann and root_start, since root_start delivered no new input, just another shell variant (which btw. IMO is only the 2nd choice because of the discussed buffer issue) for my solution. So IMHO the points should be either awarded to ahoffmann only, since he provided the first working solution, or split between ahoffmann and me, cause I delivered a shorter, more efficient variant.

Kind regards,

-XoF-
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses
Course of the Month18 days, 18 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question