Re: tail for a list of files

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: bruce <badouglas@xxxxxxxxx>
Subject: Re: tail for a list of files
On Sun, Mar 4, 2018 at 2:31 PM, Joe Zeff <joe@xxxxxxx> 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 -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx



[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux