tail for a list of files

classic Classic list List threaded Threaded
21 messages Options
12
Reply | Threaded
Open this post in threaded view
|

tail for a list of files

bruce
Hey..

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..

thoughts??

find /foo -name "*dog.dat ... tail -5    << obviously not correct. but
what would work?

thanks..
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: tail for a list of files

Clifford Snow
find /foo -name "*dog.dat" -exec tail -5 {} \;

should work. You could also add various find options like -type f to make sure its a regular file and -mtime n to get recently modified files. 

On Sat, Mar 3, 2018 at 8:15 AM, bruce <[hidden email]> wrote:
Hey..

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..

thoughts??

find /foo -name "*dog.dat ... tail -5    << obviously not correct. but
what would work?

thanks..
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]



--
@osm_seattle
OpenStreetMap: Maps with a human touch

_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: tail for a list of files

bruce
ah...

exec instead of xargs... ok...

is there a way with exec ???

thanks


On Sat, Mar 3, 2018 at 11:25 AM, Clifford Snow <[hidden email]> wrote:

> find /foo -name "*dog.dat" -exec tail -5 {} \;
>
> should work. You could also add various find options like -type f to make
> sure its a regular file and -mtime n to get recently modified files.
>
> On Sat, Mar 3, 2018 at 8:15 AM, bruce <[hidden email]> wrote:
>>
>> Hey..
>>
>> 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..
>>
>> thoughts??
>>
>> find /foo -name "*dog.dat ... tail -5    << obviously not correct. but
>> what would work?
>>
>> thanks..
>> _______________________________________________
>> users mailing list -- [hidden email]
>> To unsubscribe send an email to [hidden email]
>
>
>
>
> --
> @osm_seattle
> osm_seattle.snowandsnow.us
> OpenStreetMap: Maps with a human touch
>
> _______________________________________________
> users mailing list -- [hidden email]
> To unsubscribe send an email to [hidden email]
>
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: tail for a list of files

Joachim Backes
In reply to this post by bruce
On 03/03/18 17:15, bruce wrote:
Hi Bruce,

> Hey..
>
> 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..
>
> thoughts??
>
> find /foo -name "*dog.dat ... tail -5    << obviously not correct!
Indee

> what would work?

If I understood you correctly, then

find /foo -name "*dog.dat"|tail -5

should do the job. You forgot the pipe sign :-)


Kind regards

Joachim Backes

>
> thanks..
> _______________________________________________
> users mailing list -- [hidden email]
> To unsubscribe send an email to [hidden email]
>


--

Fedora release 27 (Twenty Seven)
Kernel-4.15.7-300.fc27.x86_64


Joachim Backes <[hidden email]>
https://www-user.rhrk.uni-kl.de/~backes/
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: tail for a list of files

bruce
On Sat, Mar 3, 2018 at 11:31 AM, Joachim Backes
<[hidden email]> wrote:

> On 03/03/18 17:15, bruce wrote:
> Hi Bruce,
>>
>> Hey..
>>
>> 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..
>>
>> thoughts??
>>
>> find /foo -name "*dog.dat ... tail -5    << obviously not correct!
>
> Indee
>
>> what would work?
>
>
> If I understood you correctly, then
>
> find /foo -name "*dog.dat"|tail -5
>
> should do the job. You forgot the pipe sign :-)
>
>
> Kind regards
>
> Joachim Backes
>
>>
>> thanks..
>> _______________________________________________
>> users mailing list -- [hidden email]
>> To unsubscribe send an email to [hidden email]
>>
>
>
> --
>
> Fedora release 27 (Twenty Seven)
> Kernel-4.15.7-300.fc27.x86_64
>
>
> Joachim Backes <[hidden email]>
> https://www-user.rhrk.uni-kl.de/~backes/
>
> _______________________________________________
> users mailing list -- [hidden email]
> To unsubscribe send an email to [hidden email]


Hi Joachim...

For a single file that works however if I want to generate the "tail"
of each file in a list of files

find /foo -name "*dog.dat" | tail -5 doesn't get the individual
files.. it gets the "tail " of the filelist.

thanks
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: tail for a list of files

bruce
In reply to this post by Clifford Snow
On Sat, Mar 3, 2018 at 11:25 AM, Clifford Snow <[hidden email]> wrote:

> find /foo -name "*dog.dat" -exec tail -5 {} \;
>
> should work. You could also add various find options like -type f to make
> sure its a regular file and -mtime n to get recently modified files.
>
> On Sat, Mar 3, 2018 at 8:15 AM, bruce <[hidden email]> wrote:
>>
>> Hey..
>>
>> 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..
>>
>> thoughts??
>>
>> find /foo -name "*dog.dat ... tail -5    << obviously not correct. but
>> what would work?
>>
>> thanks..
>> _______________________________________________
>> users mailing list -- [hidden email]
>> To unsubscribe send an email to [hidden email]
>
>
>
>
> --
> @osm_seattle
> osm_seattle.snowandsnow.us
> OpenStreetMap: Maps with a human touch
>
> _______________________________________________
> users mailing list -- [hidden email]
> To unsubscribe send an email to [hidden email]
>

Hey Cliff!!

Thanks.. works .. but I forgot one thing...

Is there a way to list the "file" prior to the tail or would that
require a bash/shell script.. I could have sworn that I've seen how to
accomplish this a while ago...  arggh!

thanks..
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: tail for a list of files

Samuel Sieb
In reply to this post by bruce
On 03/03/2018 08:15 AM, 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..
>
> thoughts??
>
> find /foo -name "*dog.dat ... tail -5    << obviously not correct. but
> what would work?

When you have more than one file you can't use "-5", you have to use the
full option which is "-n 5".  So this should work:

tail -n 5 $(find /foo -name "*dog.dat")
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: tail for a list of files

Clifford Snow
In reply to this post by bruce


On Sat, Mar 3, 2018 at 8:40 AM, bruce <[hidden email]> wrote:

Thanks.. works .. but I forgot one thing...

Is there a way to list the "file" prior to the tail or would that
require a bash/shell script.. I could have sworn that I've seen how to
accomplish this a while ago...  arggh!

For that I think you need to use xarg as:

find /foo -name "*dog.dat" -print0 | xargs -0  tail -n5 {} \;
 

--
@osm_seattle
OpenStreetMap: Maps with a human touch

_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: tail for a list of files

Clifford Snow
Correction - I shouldn't have copy and pasted. drop the {} \; from the script

find /foo -name "*dog.dat" -print0 | xargs -0  tail -n5

On Sat, Mar 3, 2018 at 10:44 AM, Clifford Snow <[hidden email]> wrote:


On Sat, Mar 3, 2018 at 8:40 AM, bruce <[hidden email]> wrote:

Thanks.. works .. but I forgot one thing...

Is there a way to list the "file" prior to the tail or would that
require a bash/shell script.. I could have sworn that I've seen how to
accomplish this a while ago...  arggh!

For that I think you need to use xarg as:

find /foo -name "*dog.dat" -print0 | xargs -0  tail -n5 {} \;
 

--
@osm_seattle
OpenStreetMap: Maps with a human touch



--
@osm_seattle
OpenStreetMap: Maps with a human touch

_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: tail for a list of files

Roger Heflin
find /foo -name "*dog.dat" -ls -exec tail -f {} \;

-print will list only the filename
-ls will list the long dir entry.
{} is needed to deliver the filename you are working with.
\; is needed to signal the end of the command.

On Sat, Mar 3, 2018 at 12:45 PM, Clifford Snow <[hidden email]> wrote:

> Correction - I shouldn't have copy and pasted. drop the {} \; from the
> script
>
> find /foo -name "*dog.dat" -print0 | xargs -0  tail -n5
>
> On Sat, Mar 3, 2018 at 10:44 AM, Clifford Snow <[hidden email]>
> wrote:
>>
>>
>>
>> On Sat, Mar 3, 2018 at 8:40 AM, bruce <[hidden email]> wrote:
>>>
>>>
>>> Thanks.. works .. but I forgot one thing...
>>>
>>> Is there a way to list the "file" prior to the tail or would that
>>> require a bash/shell script.. I could have sworn that I've seen how to
>>> accomplish this a while ago...  arggh!
>>>
>> For that I think you need to use xarg as:
>>
>> find /foo -name "*dog.dat" -print0 | xargs -0  tail -n5 {} \;
>>
>>
>> --
>> @osm_seattle
>> osm_seattle.snowandsnow.us
>> OpenStreetMap: Maps with a human touch
>
>
>
>
> --
> @osm_seattle
> osm_seattle.snowandsnow.us
> OpenStreetMap: Maps with a human touch
>
> _______________________________________________
> users mailing list -- [hidden email]
> To unsubscribe send an email to [hidden email]
>
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: tail for a list of files

Jonathan Ryshpan
In reply to this post by bruce
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?


_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: tail for a list of files

R. G. Newbury
In reply to this post by bruce

> From: Jonathan Ryshpan <[hidden email]>
> Subject: Re: tail for a list of files
> To: [hidden email]
> Message-ID: <[hidden email]>
> 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
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: tail for a list of files

Joe Zeff
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?
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: tail for a list of files

bruce
On Sun, Mar 4, 2018 at 2:31 PM, Joe Zeff <[hidden email]> 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 -- [hidden email]
> To unsubscribe send an email to [hidden email]
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: tail for a list of files

R. G. Newbury
In reply to this post by bruce
From: Joe Zeff<[hidden email]>
> 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?

That exercise was left for those adventurous students with an inquiring
mind to attempt and to ascertain the answer for themselves....

But for those without a computer to run the code or the intellectual
musculature to open a console and type a line or two, (or for that
matter, read this, since you obviously cannot own a computer..), the
answer is:

$find .  -name "*.pdf" | sort
./123.pdf
./124.pdf
./125.pdf
./126.pdf

Geoff
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: tail for a list of files

Joe Zeff
On 03/04/2018 01:07 PM, R. G. Newbury wrote:

>
> That exercise was left for those adventurous students with an inquiring
> mind to attempt and to ascertain the answer for themselves....
>
> But for those without a computer to run the code or the intellectual
> musculature to open a console and type a line or two, (or for that
> matter, read this, since you obviously cannot own a computer..), the
> answer is:
>
> $find .  -name "*.pdf" | sort
> ./123.pdf
> ./124.pdf
> ./125.pdf
> ./126.pdf

Thank you.  I'd do a little more work on this for you, if it weren't for
the gratuitous insults.
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: tail for a list of files

Samuel Sieb
In reply to this post by R. G. Newbury
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.
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: tail for a list of files

Samuel Sieb
In reply to this post by bruce
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
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: tail for a list of files

Samuel Sieb
In reply to this post by R. G. Newbury
On 03/04/2018 01:07 PM, R. G. Newbury wrote:

> From: Joe Zeff<[hidden email]>
>> 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?
>
> That exercise was left for those adventurous students with an inquiring
> mind to attempt and to ascertain the answer for themselves....
>
> But for those without a computer to run the code or the intellectual
> musculature to open a console and type a line or two, (or for that
> matter, read this, since you obviously cannot own a computer..), the
> answer is:

I think the confusion here is whether you were indirectly asking a
question or answering an unasked question.
_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: tail for a list of files

R. G. Newbury
In reply to this post by bruce
> From: bruce <[hidden email]>
> Subject: Re: tail for a list of files
> On Sun, Mar 4, 2018 at 2:31 PM, Joe Zeff <[hidden email]> 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

Ahh, well you should *said* so. We all went running off in all
directions *at once*!
This time I created 4 files 123.txt, 124.txt etc. each with 10 lines
numbered 1 to 10

To get the last 5 lines of every ".txt" file
Use:
$ for file in $(find .  -name "*.txt"); do cat $file | tail -n 5; done


To display the filename, and last 5 lines of each of the last 2 files
Use:
$ for file in $(find .  -name "*.txt" | sort | tail -n 2); do echo
$file; cat $file | tail -n 5; done

Output is:
./125.txt
7
8
9
10

./126.txt
7
8
9
10

YOu may have to be careful about the use of the 'sort' pipe: you may
need to add a switch to enforce a particular sort order. Sort can leave
you out of sorts that way.

Geoff









_______________________________________________
users mailing list -- [hidden email]
To unsubscribe send an email to [hidden email]
12