[svlug] edit a 1GB file

William R Ward bill at wards.net
Mon Mar 31 11:03:05 PST 2003

Rufoo writes:
>--- William R Ward <bill at wards.net> wrote:
>> >> 
>> >> perl -pi -e 's/^some line$/some other line/g'
>> >> 
>> >> "man perlrun" for more.
>> >
>> >Why even perl when sed can do the same. 
>> How?  To the best of my knowledge, the equivalent in
>> sed would require
>> adding a redirect and a "mv" command.  That's not
>> just sed, that's
>> sed, shell, and mv.  Perl lets you do it in one
>> command.
>Yeah, thats right. How does Perl do it?
>C:\WINDOWS\Desktop>perl --help > x.txt
>C:\WINDOWS\Desktop>perl -pi -e 's/record/hello/g'
>Can't do inplace edit without backup.
>I am not good at perl, I havent read perlrun yet. but
>does it really do inplace edit? How is the inplace
>edit implemented? Let me think ... 

Oh, you're using MS-DOS.  Sorry I thought this was a question about

The MS-DOS filesystem doesn't support in-place edit without backup, as
the error message said.  So you have to specify a backup extension
after the -i otpion.  Try this instead:

perl -pi.bak -e 's/record/hello/g'

Now you will have a file x.txt.bak (NOT x.bak) that contains the
original version, and x.txt contains the updated version.

It's a good idea to always do the backup even on Linux/Unix anyway, in
case you make a mistake in the edit command, so you don't lose the
original version.


William R Ward            bill at wards.net          http://www.wards.net/~bill/
"A foolish consistency is the hobgoblin of little minds, adored by
 little statesmen and philosophers and divines."        - Emerson

More information about the svlug mailing list