Re: a technical how to
On Tuesday 09 December 2003 02:51, homeyra g wrote: So, I hope this is the right address for this type of question. If not would you please forward this and/or let me know the correct address. Thanks, Here is the question: How to truncate a file from the begining to a certain point in the file? There's two commands that might be helpful: truncate(1) dd(1) Read about them in the man pages. Hope I was of some help! Best regards, Paul ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: a technical how to
Hiya, no-one has mentioned 'head' yet: head -100 file newfile to save the first 100 lines of file into newfile. You can also use a combination of head and tail to take a portion of the file, e.g: head -100 file | tail -3 newfile to save off lines 98,99 and 100 of file into newfile. I've known this to be useful when trying to extract certain lines from mammoth files. If, by a certain point you meant, for example, up to some general regex then you could employ some perl: cat file | perl -e 'while () { exit if /REGEX/; print }' newfile I know you can do similar things in sed and awk, but I don't know the syntax off the top of my head, and don't have my notes to hand. David On Tue, 9 Dec 2003, Charles Swiger wrote: On Dec 8, 2003, at 8:51 PM, homeyra g wrote: Here is the question: How to truncate a file from the begining to a certain point in the file? The question is whether this file is ASCII text so line-based tools (such as tail) work, or whether you are truncating a binary file, in which case split -b is probably a better bet. If you've got a logfile named /var/log/messages, and you want to truncate that to the last 100 lines: mv /var/log/messages /var/log/messages.$$ tail -100 /var/log/messages.$$ /var/log/messages rm -f /var/log/messages.$$ Use wc -l and grep -n to identify where to truncate the file if it's not a fixed size that you want... -- -Chuck ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: a technical how to
no-one has mentioned 'head' yet: head -100 file newfile to save the first 100 lines of file into newfile. You can also use a combination of head and tail to take a portion of the file, e.g: head -100 file | tail -3 newfile to save off lines 98,99 and 100 of file into newfile. I've known this to be useful when trying to extract certain lines from mammoth files. If, by a certain point you meant, for example, up to some general regex then you could employ some perl: cat file | perl -e 'while () { exit if /REGEX/; print }' newfile I know you can do similar things in sed and awk, but I don't know the syntax off the top of my head, and don't have my notes to hand. David On Tue, 9 Dec 2003, Charles Swiger wrote: On Dec 8, 2003, at 8:51 PM, homeyra g wrote: Here is the question: How to truncate a file from the begining to a certain point in the file? The question is whether this file is ASCII text so line-based tools (such as tail) work, or whether you are truncating a binary file, in which case split -b is probably a better bet. If you've got a logfile named /var/log/messages, and you want to truncate that to the last 100 lines: mv /var/log/messages /var/log/messages.$$ tail -100 /var/log/messages.$$ /var/log/messages rm -f /var/log/messages.$$ Use wc -l and grep -n to identify where to truncate the file if it's not a fixed size that you want... -- -Chuck ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: a technical how to
So, I hope this is the right address for this type of question. If not would you please forward this and/or let me know the correct address. Is it a text or binary file? First, I suggest working from a copy of the file for safety sake. For a text file, Use vi. Count down to which line is the last one you want to get rid of (lets say you want to get rid of 1-1152 and keep from 1153-end). Then, in vi, put your cursor on the first line and do '1152dd'. save the file off with ':wq' and voila, you got it. For a binary file, use dd and tell it to skip the bytes in front and start copying from there to end to the new file. You may also have to play around with blocksize and notrunc to get just what you want if you need to break it on some odd boundary. jerry Thanks, Here is the question: How to truncate a file from the begining to a certain point in the file? __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/ ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: a technical how to
On Dec 8, 2003, at 8:51 PM, homeyra g wrote: Here is the question: How to truncate a file from the begining to a certain point in the file? The question is whether this file is ASCII text so line-based tools (such as tail) work, or whether you are truncating a binary file, in which case split -b is probably a better bet. If you've got a logfile named /var/log/messages, and you want to truncate that to the last 100 lines: mv /var/log/messages /var/log/messages.$$ tail -100 /var/log/messages.$$ /var/log/messages rm -f /var/log/messages.$$ Use wc -l and grep -n to identify where to truncate the file if it's not a fixed size that you want... -- -Chuck ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
a technical how to
So, I hope this is the right address for this type of question. If not would you please forward this and/or let me know the correct address. Thanks, Here is the question: How to truncate a file from the begining to a certain point in the file? __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/ ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: a technical how to
On Tuesday 09 December 2003 02:51, homeyra g wrote: So, I hope this is the right address for this type of question. If not would you please forward this and/or let me know the correct address. Thanks, Here is the question: How to truncate a file from the begining to a certain point in the file? Have a look at sed. Sorry can't help with syntax and I'm sure one can also do the same with perl or awk or whatever. But for the first, man (1) sed will help with 'cat yourfile | sed -youroptions' e.g. You can also use vi (if it's a regular textfile with less than hundreds of megs), find your endpoint with e.g /YourEndKeyWord and do in instruction mode a dG, after that save. -Harry __ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/ ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] pgp0.pgp Description: signature
Re: a technical how to
On Mon, Dec 08, 2003 at 05:51:25PM -0800, homeyra g wrote: Here is the question: How to truncate a file from the begining to a certain point in the file? You can do this in vi. If you are trying to keep only the beginning, you'd do this, where ++ is the first line you don't want: :++,$d If you only want the chunk at the end there are a couple of good ways: :0,++-1d or, if you want to keep the original file: :++-1,$w newfile Where newfile is the file name you want to keep your output in. vi does a whole lot of fine things, and because it is nearly ubiquitous in UNIX it may be worth using for such things. If you want to do this from the command line you can do so with ex scripts. This is the use vi for all text processing approach. Perl, sed, awk, shell scripting; they'll all do the same job. Pick a tool and you'll get a lot of mileage out of it. Have fun. -- yours, William ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: a technical how to
Harald Schmalzbauer wrote: On Tuesday 09 December 2003 02:51, homeyra g wrote: So, I hope this is the right address for this type of question. If not would you please forward this and/or let me know the correct address. Thanks, Here is the question: How to truncate a file from the begining to a certain point in the file? Have a look at sed. Sorry can't help with syntax and I'm sure one can also do the same with perl or awk or whatever. But for the first, man (1) sed will help with 'cat yourfile | sed -youroptions' e.g. You can also use vi (if it's a regular textfile with less than hundreds of megs), find your endpoint with e.g /YourEndKeyWord and do in instruction mode a dG, after that save. -Harry And if you use PHP, you could do a fairly easy script also, via the CLI. Lots of shell scripting stuff out there, isn't there? KDK ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: a technical how to
In the last episode (Dec 08), Kevin D. Kinsey, DaleCo, S.P. said: Harald Schmalzbauer wrote: On Tuesday 09 December 2003 02:51, homeyra g wrote: So, I hope this is the right address for this type of question. If not would you please forward this and/or let me know the correct address. Thanks, Here is the question: How to truncate a file from the begining to a certain point in the file? If you're writing a script, use the /usr/bin/truncate command. If you're writing a C program, use the truncate() function. -- Dan Nelson [EMAIL PROTECTED] ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: a technical how to
In the last episode (Dec 08), Kevin D. Kinsey, DaleCo, S.P. said: Harald Schmalzbauer wrote: On Tuesday 09 December 2003 02:51, homeyra g wrote: So, I hope this is the right address for this type of question. If not would you please forward this and/or let me know the correct address. Thanks, Here is the question: How to truncate a file from the begining to a certain point in the file? If you're writing a script, use the /usr/bin/truncate command. If you're writing a C program, use the truncate() function. truncate() essentially alters the end-of-file position, by decreasing it (truncating the file) or increasing it (extending the file.) I think what the requestor wants is a way to adjust the start-of-file position, which would effectively truncate [sic] a file from the beginning to a certain point in the file. One way to accomplish this is as follows: split -b 1024 /path/to/data rm files that represent data to truncate cat * data.new -- Matt Emmerton ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]