Re: removing lines from a file
From: Alan Connor (zzzzzz_at_xxx.yyy)
Date: 06/29/04
- Next message: Kevin Collins: "Re: Checking passwords in shell scripts"
- Previous message: Peter J. Acklam: "Re: removing lines from a file"
- In reply to: John W. Krahn: "Re: removing lines from a file"
- Next in thread: Charles Demas: "Re: removing lines from a file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 28 Jun 2004 22:27:52 GMT
On Mon, 28 Jun 2004 21:07:31 GMT, John W. Krahn <krahnj@acm.org> wrote:
>
>
> RMH wrote:
>>
>> Does someone Know how can I remove the two last lines from a file and
>> save the modification?
>
> perl -i~ -pe'BEGIN{@x = 0} push @x, tell ARGV; END{ truncate $ARGV, $x[-3] }' yourfile
PERL!!!!!
"There's a housefly, Myra. Get the tactical nuke! Hurry now, or we might
MISS it!"
:-)
ed -s yourfile <<XXXX
$-1,$d
.
wq
XXXX
All done, and you can do that on the commandline with bash2.
With another shell:
echo -e "$-1,$d\n.\nwq\n" | ed -s yourfile
/bin/ed 25K and a script that's 1/2 as long...
AC
-- ed(1) Check out the original tutorials by Brian W. Kernighan at the Ed Home Page http://tinyurl.com/2aa6g
- Next message: Kevin Collins: "Re: Checking passwords in shell scripts"
- Previous message: Peter J. Acklam: "Re: removing lines from a file"
- In reply to: John W. Krahn: "Re: removing lines from a file"
- Next in thread: Charles Demas: "Re: removing lines from a file"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|