copy last 10000+ lines of large text file to a temporary file
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
copy last 10000+ lines of large text file to a temporary file
Hello,
I need to periodically copy the last 81424 lines of a large (> 5GB) text file that is an output of a program to a temp file. The text file is not arranged in columns, but it does have a repetitive structure (repeated every 81424 lines). The program is continually writing new data to the text file. I need to scan this data at very small time intervals (less than every 15 sec.) to stop the program as soon as a certain condition is met in the data.
I have tried the following, but I seem to not be able to tail more than 10000 lines at a time:
tail -n 81424 f.txt > ftemp.txt
I also tried these things but they take too much wall clock time (4min+)
1. counting the number of lines in the file, using `cat f.txt | wc -l` and then using head and tail in a pipeline to print out the last 81424 lines of the file (lines #totallines-81424-1 to #totallines).
2. using sed from the infamous 'sed one-liners' to output the last 81424 lines:
sed -e :a -e '$q;N;81425,$D;ba' f.txt
Any suggestions? Is there a way to change the limit on the number of lines that can be output using tail? Can I copy the last X-sized chunk (in bytes or something) to another file somehow?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.