From: "Brandon Mitchell" <[EMAIL PROTECTED]>
To: Anna <[EMAIL PROTECTED]>, [email protected]
Subject: Re: [RLUG] quick question
Date: Wed, 28 Jun 2006 17:26:47 -0700
This is an interesting problem, and seems to be revealing a little bit
about what type of user/admin is in each of us.
So where's Nick with an Emacs Lisp macro for this task? :P
watching a $2.5 million airship get completely and spectacularly destroyed
in under 5 seconds by what the FAA declared literally "an act of God" (more
info at the barbeque)
as far as I know there's no way to alter the file without loading the whole
thing in emacs... if you did though it would be a matter of
C-<space>
C-u 300
C-n
C-w
C-x s
to remove the 1st 300 lines of the file and resave it.
if you wanted to repeat this action a few times you could make it a keyboard
macro by sandwiching it between C-x ( and C-x ). then hit F5 or whatever
when you want to perform this action. and of course if this action goes from
frequent to habitual you could make your elisp function and bind it
permanently to a key ;-)
then again, you could do this in common lisp without having two copies of
the file or having to have the whole file in memory by using two seperate
filestreams on the same file
(with-open-file (in #p"/path/to/bigfile" :direction :input)
(with-open-file (out #p"/path/to/bigfile"
:direction :output
:if-exists :overwrite)
(dotimes (i 300) (read-line in))
(handler-case
(loop (princ (read-line in) out) (terpri out))
(error ()))
although the HyperSpec (common lisp's language spec) permits WITH-OPEN-FILE
to put a lock on a file when it is opened so maybe you might have to use the
more klunky primitives OPEN and CLOSE rather than WITH-OPEN-FILE on some
implimentations. I know it will work with ACL >=7
Nick
On 6/28/06, Anna <[EMAIL PROTECTED]> wrote:
find out which byte terminates the first 300 lines. maybe...
~$ BYTES=$(head -300 nameofbigfile.txt | wc -c)
then use that info with dd skip the first part of the input file...
~$ dd if=nameofbigfile.txt of=truncatedversion.pl ibs=$BYTES skip=1
one of many ways, I'm sure. I think this way should be pretty fast
because it works on a line by line basis for just a small part of the
file. The rest, with dd, is done in larger pieces.
- Anna
On Wed, Jun 28, 2006 at 01:01:03PM -0700, Grant Kelly wrote:
> Alright unix fans, who can answer this the best?
>
> I have a text file, it's about 2.3 GB. I need to delete the first 300
> lines, and I don't want to have to load the entire thing into an
> editor.
>
> I'm trying `sed '1,300d' inputfile > output file` but it's taking a
> long time (and space) to output everything to the new file.
>
> There has got to be a better way, a way that can do this in-place...
>
>
> Grant
>
> _______________________________________________
> RLUG mailing list
> [email protected]
> http://lists.rlug.org/mailman/listinfo/rlug
_______________________________________________
RLUG mailing list
[email protected]
http://lists.rlug.org/mailman/listinfo/rlug
--
If UNIX doesn't have the solution you have the wrong problem.
UNIX is simple, but it takes a genius to understand it's simplicity.
_______________________________________________
RLUG mailing list
[email protected]
http://lists.rlug.org/mailman/listinfo/rlug
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
_______________________________________________
RLUG mailing list
[email protected]
http://lists.rlug.org/mailman/listinfo/rlug