From: Jonathan Ryshpan jonrysh@pacbell.net Subject: Re: tail for a list of files To: users@lists.fedoraproject.org Message-ID: 1520171408.2173.42.camel@pacbell.net Content-Type: multipart/alternative; boundary="=-PuQtDYwItgjfcLx2Crff"
--=-PuQtDYwItgjfcLx2Crff Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit
On Sat, 2018-03-03 at 11:15 -0500, bruce wrote:
Trying to figure out how to do a single line cmd (it should be possible right??) to do a tail -5 for a list of files???
I thought I could combine find with exec/xargs and tail to generate the list of files/tail data.. But couldn't figure out the syntax..
find /foo -name "*dog.dat ... tail -5 << obviously not correct. but what would work?
I think the easy way is $ find /foo -name "*dog.dat" | xargs tail -n5 or am I missing something?
I created 4 pdf files using 'touch 123.pdf' through '126.pdf'
find . -name "*.pdf" | tail -n 2
does not 'find' the files in canonical order: it outputs 124.pdf and 126.pdf
Neither does .... | xargs tail -n 2
Trying: tail -n 2 $(find . -name "*.pdf") gives: ==> ./125.pdf <==
==> ./123.pdf <==
==> ./124.pdf <==
==> ./126.pdf <==
NOT in order and ignores the 'tail -n 2'
tail -n 2 $(find . -name "*.pdf"| sort) gives the files in order, but ignores the tail count.
HOWEVER this works: find . -name "*.pdf" | sort | tail -n 2 ./125.pdf ./126.pdf
Geoff
On Sun, Mar 4, 2018 at 2:31 PM, Joe Zeff joe@zeff.us wrote:
On 03/04/2018 11:15 AM, R. G. Newbury wrote:
find . -name "*.pdf" | tail -n 2
does not 'find' the files in canonical order: it outputs 124.pdf and 126.pdf
What does it print if you don't run it through tail?
um.. hey guys....
I wanted to get the last X lines of each file from an input/wildcard list of files !!
so.. I wanted the last 5 lines of the 126.pdf as well as the last 5 lines of the 125.pdf... --NOT the last X files from a list of files..
thanks
users mailing list -- users@lists.fedoraproject.org To unsubscribe send an email to users-leave@lists.fedoraproject.org
On 03/04/2018 11:15 AM, R. G. Newbury wrote:
I created 4 pdf files using 'touch 123.pdf' through '126.pdf'
find . -name "*.pdf" | tail -n 2
does not 'find' the files in canonical order: it outputs 124.pdf and 126.pdf
The find command lists the files in whatever order the filesystem returns them, it does not do any sorting.
On 03/04/2018 11:43 AM, bruce wrote:
um.. hey guys....
I wanted to get the last X lines of each file from an input/wildcard list of files !!
so.. I wanted the last 5 lines of the 126.pdf as well as the last 5 lines of the 125.pdf... --NOT the last X files from a list of files..
There were already at least two different solutions posted.
tail -n 5 $(find /foo -name "*dog.dat") find /foo -name "*dog.dat" -print0 | xargs -0 tail -n5
On Sun, Mar 04, 2018 at 02:32:03PM -0800, Samuel Sieb wrote:
On 03/04/2018 11:43 AM, bruce wrote:
I wanted to get the last X lines of each file from an input/wildcard list of files !!
There were already at least two different solutions posted.
tail -n 5 $(find /foo -name "*dog.dat") find /foo -name "*dog.dat" -print0 | xargs -0 tail -n5
I'll add a third. Difference is printing of the filename. The two above depend on tail to print the name IF there are multiple arguments. If there is only one match by find or if xargs' last group no filename will be printed. This could be avoided by adding /dev/null to tail's arg list.
The first solution above could exceed the system or shell's maximum command line length.
ASolution where find prints the filename and calls a separate tail for each file is:
find /foo -type f -name "*dog.dat" -print -exec tail -n 5 {} ';'
Jon