- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to chop off the last part of a large file?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 10:32 AM
06-20-2003 10:32 AM
I need to chop off the last part of a very large file. The file is so large that I can't copy and move it back into place. Does anyone know of a command to allow me to do this to a file without a copy?
TIA,
John
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 10:34 AM
06-20-2003 10:34 AM
Re: How to chop off the last part of a large file?
tail
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 10:36 AM
06-20-2003 10:36 AM
Re: How to chop off the last part of a large file?
There any many options.
You can use split to split the files into many chunks(files). check man split.
You can view say first 100 lines using head -100 server.out
You can also use tail to see the last part of the file say 100 lines from below tail -100 server.out.
HTH,
Umapathy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 10:36 AM
06-20-2003 10:36 AM
Re: How to chop off the last part of a large file?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 10:38 AM
06-20-2003 10:38 AM
Re: How to chop off the last part of a large file?
perl -e 'truncate("myfile",10000000)'
This will chop off everything in "myfile" beyond the 10,000,000th byte.
Man 2 truncate for details.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 10:38 AM
06-20-2003 10:38 AM
Re: How to chop off the last part of a large file?
tail -N file > lastN.file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 10:42 AM
06-20-2003 10:42 AM
Re: How to chop off the last part of a large file?
I guess I was not very clear. I want to keep the first part of a file and discard the last parts without rewriting the file. I would really like to chop a file off at say line 900000 and do the operation "in place".
Thanks,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 10:52 AM
06-20-2003 10:52 AM
Re: How to chop off the last part of a large file?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 11:01 AM
06-20-2003 11:01 AM
Re: How to chop off the last part of a large file?
You can use the head command. See the man pages for more information. It does the opposite than the tail command.
head -n 100 filename > newfilname
Regards,
Dario
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 11:02 AM
06-20-2003 11:02 AM
Re: How to chop off the last part of a large file?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 11:06 AM
06-20-2003 11:06 AM
Re: How to chop off the last part of a large file?
The perl function truncate will help you
and as A. Clay Stephenson writen that it's
not suporten on all kind of unix systems
you also have library that implement truncate
for c/c++ that you could use not shure about
the name something about filetools.
Caesar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 11:13 AM
06-20-2003 11:13 AM
Re: How to chop off the last part of a large file?
Can't wait to finally get time to open the Perl books.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 11:17 AM
06-20-2003 11:17 AM
Re: How to chop off the last part of a large file?
Please disregard my approach since you will have to re-direct to a file.
Regards,
Dario
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 11:21 AM
06-20-2003 11:21 AM
Re: How to chop off the last part of a large file?
num=9000001 #number of lines to save + 1.
ex -s +"$num,$ d|wq" $yourfile
of course you might want to do some testing to verify there is at least $num lines in your file before doing this. and, I would guess that ex does create a scratch file copy of $yourfile in /var/tmp, so you'll need some free disk space there.
I'm sure there is a way to remove lines in place using perl also.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 11:39 AM
06-20-2003 11:39 AM
Solution# perl -e'$f=$ARGV[0];<>for 1..9_000;truncate$f,tell' file_to_truncate
example is for 1 file only!
Enjoy, have FUN! H.Merijn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 12:06 PM
06-20-2003 12:06 PM
Re: How to chop off the last part of a large file?
Thanks to all,
John
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 12:12 PM
06-20-2003 12:12 PM
Re: How to chop off the last part of a large file?
My second reason was that I question the need for such a command unless one might want to intentionally truncate a log to hide one's tracks in which case he would be well advised to make sure ctime, mtime, and atime are 'fixed' as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2003 12:33 PM
06-20-2003 12:33 PM
Re: How to chop off the last part of a large file?
To figure out the size of line you will
need to know the size of line that's mean
scan all file and get size of every line
than in the end truncate what you want to
remove.
Best for you is to made the whole script on perl.
Caesar