Re: remove last and first three lines from a file
From: Robert Katz (katz_at_hp.com)
Date: 12/28/04
- Next message: Kenny McCormack: "Re: Script Header"
- Previous message: Kenny McCormack: "Re: How do I detect which shell (ksh, bash, csh, zsh, tcsh) is currently used?"
- In reply to: John Savage: "Re: remove last and first three lines from a file"
- Next in thread: John Savage: "Re: remove last and first three lines from a file"
- Reply: John Savage: "Re: remove last and first three lines from a file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 28 Dec 2004 19:44:34 GMT
John Savage wrote:
> "Prince" <gspk@yahoo.com> writes:
>
>>I forgot to mention, the dificulty I have is deleting the last three
>>lines. I can use sed '1,3d' to delete the first three.
>
>
> Any great need for efficiency? If not ....
>
> sed '1,3d;$d' datafile | sed '$d' | sed '$d'
>
> or, sed '1d;$d' datafile | sed '1d;$d' | sed '1d;$d'
In classical sed, not GNU, in which
"If no next line of input is available, the N command verb shall branch
to the end of the script and quit without starting a new cycle or
copying the pattern space to standard output."
sed '
1,3d
4{N;N;}
N;P;D'
This is not as easily generalized as the awk routine.
-- Regards, ---Robert
- Next message: Kenny McCormack: "Re: Script Header"
- Previous message: Kenny McCormack: "Re: How do I detect which shell (ksh, bash, csh, zsh, tcsh) is currently used?"
- In reply to: John Savage: "Re: remove last and first three lines from a file"
- Next in thread: John Savage: "Re: remove last and first three lines from a file"
- Reply: John Savage: "Re: remove last and first three lines from a file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|