in reply to Re: Strange problem trying to clean garbage from start of mailbox file
in thread Strange problem trying to clean garbage from start of mailbox file

If you don't pipe the sed through more it simple wipes the file. Good idea to close the file handle first. Dosn't do anything for the problem though.
  • Comment on Re^2: Strange problem trying to clean garbage from start of mailbox file

Replies are listed 'Best First'.
Re^3: Strange problem trying to clean garbage from start of mailbox file
by rhesa (Vicar) on Feb 02, 2006 at 23:09 UTC
    i'm not a sed expert by any stretch of the imagination, but wouldn't
    sed -i -e '1d' $file
    be a more idiomatic way to write it?

    I believe that piping output into the file you're stream-editing is not the most reliable thing to do. In fact, I'm pretty sure that's why your buffering by "|more" prevents the file from being clobbered.

      I'm no sed expert either, in fact this is the first time I've used it.

      That's a much nicer way of doing things, cheers :)
      Damn, sed on BSD dosn't have the -i option. I'll have a look at the man page to see if there is another way to do an in-place edit.
        Um, what sort of BSD are you using? When I do "man sed" on freebsd (and the bsd-based darwin on my mac), I see:
        -i extension Edit files in-place, saving backups with the specified extension +. If a zero-length extension is given, no backup will be saved. I +t is not recommended to give a zero-length extension when in-place editing files, as you risk corruption or partial content in situ +- ations where disk space is exhausted, etc.