-----Original Message----- >From: [EMAIL PROTECTED] >Sent: Aug 11, 2007 9:58 PM >To: beginners@perl.org >Subject: Re: Replacing the n'th line with the new line > >On Aug 9, 6:46 am, [EMAIL PROTECTED] (Chas Owens) wrote: >> On 8/8/07, Jeff Pang <[EMAIL PROTECTED]> wrote: >> snip> perl -pi -e '$i++;s/^.*$/something/ if $i==10' your_file >> >> snip >> >> There is no need to keep track of the number of lines with a separate >> variable. Perl already does this with the $. variable. Also, a regex >> that replaces everything is pointless, just assign to $_. >> >> perl -pi -le '$_ = "something" if $. == 10' your_file > >So if this was in a script rather than a oneliner how would it work? >I was playing and can not get it to work in an actual test script. >
Why not working?See this test, $ cat file.txt # /etc/profile # System wide environment and startup programs, for login setup # Functions and aliases go in /etc/bashrc $ perl -pi -e '$_="something\n" if $.==2' file.txt $ cat file.txt # /etc/profile something # System wide environment and startup programs, for login setup # Functions and aliases go in /etc/bashrc -- Jeff Pang <[EMAIL PROTECTED]> http://home.arcor.de/jeffpang/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/