find and file info

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
mmatharuAsked:
Who is Participating?
 
ahoffmannCommented:
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
 
XoFCommented:
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
 
root_startCommented:
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
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
XoFCommented:
> 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
 
JJSmithCommented:

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
 
gheistCommented:
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
 
XoFCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.