Re: perl -pie "???"
by BrowserUk (Patriarch) on Aug 17, 2004 at 21:55 UTC
|
perl -pi.bak -e"BEGIN{<>}" file
## Or
perl -pi -e 'BEGIN{<>}' file
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algorithm, algorithm on the code side." - tachyon
| [reply] [d/l] |
•Re: perl -pie "???"
by merlyn (Sage) on Aug 17, 2004 at 22:34 UTC
|
I don't see any solutions yet that work if there's more than one file. Here's my entry:
perl -ni -e 'print unless 1 .. 1; close ARGV if eof' file1 file2 file3
+ ...
| [reply] [d/l] |
|
perl -0777 -pe's/^.*\n//' any number of files
This won't work correctly on files with a single line and no terminating newline, though. If that is a concern, the following is necessary:
perl -0777 -pe's/^.*(?:\n|\z)//' any number of files
I really wish there was a metacharacter for "either newline or end of string" as the counterpart to $ — this isn't the first time it would have been handy.
Makeshifts last the longest.
| [reply] [d/l] [select] |
|
perl -0777 -pe's/^.*\n?//'
| [reply] [d/l] |
Re: perl -pie "???"
by diotalevi (Canon) on Aug 17, 2004 at 21:23 UTC
|
perl -nie 'print if $. > 1'
# Better
perl -ie '<>; print while <>'
Oops. I don't use -i enough to realize that the following text is an argument for it.
perl -ibak -n -e 'print if $. > 1'
# Better
perl -ibak -e '<>; print while <>'
| [reply] [d/l] [select] |
|
perl -ni -e 'print if 2 .. 0' file
Hugo | [reply] [d/l] |
|
| [reply] [d/l] |
|
Hmmm it must be how I am invoking perl.
Here's the line I want to get rid of ...
$ head -1 DAR_RH9_install/index.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http:/
+/www.w3.org/TR/html4/loose.dtd">
Here's what I tried ...
$ perl -nie 'print if $. > 1' DAR_RH9_install/index.html
Can't open perl script "print if $. > 1": No such file or directory
$ perl -ie '<>; print while <>' DAR_RH9_install/index.html
Can't open perl script "<>; print while <>": No such file or directory
What the heck I am doing wrong here?
Plankton: 1% Evil, 99% Hot Gas. |
| [reply] [d/l] [select] |
|
| [reply] [d/l] [select] |
|
perl -ni -e '...' file
Hugo | [reply] [d/l] [select] |
|
Change perl -nie ... to perl -ni -e .... -i accepts an optional argument, so a space is needed after it.
| [reply] [d/l] [select] |
|
perl -ni -e 'print if $. > 1' filename
| [reply] |
Re: perl -pie "???"
by jmcnamara (Monsignor) on Aug 17, 2004 at 22:09 UTC
|
perl -i -ne 'print if $.-1' file
perl -i -pe 'goto LINE if $. == 1' file
perl -i -pe '$_=$+if!$if++' file
--
John.
| [reply] [d/l] |
Re: perl -pie "???"
by ysth (Canon) on Aug 17, 2004 at 22:11 UTC
|
Please, monks, remember to spell words whenever possible.
Use perl -wi -ne and perl -wi -pe. perl -li -nUx should work too. | [reply] |
Re: perl -pie "???"
by Chady (Priest) on Aug 18, 2004 at 05:52 UTC
|
here's my take, since you want -p and not -n
perl -pi -e '$_="" if $i++' file
Update: oops! wrote it backwards. Thanx TZapper for pointing it out.
perl -pi -e '$_="" unless $i++' file
He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.
Chady | http://chady.net/
| [reply] [d/l] [select] |
|
Chady, your one-liner deletes everything but the first line.
| [reply] |
Re: perl -pie "???"
by hardburn (Abbot) on Aug 17, 2004 at 21:24 UTC
|
Perhaps next if $. == 1?
"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.
| [reply] [d/l] |
|
while ( <> )
{
# YOUR CODE GOES HERE
}
continue
{
# next() resumes here.
print
}
| [reply] [d/l] |
Re: perl -pie "???"
by Anonymous Monk on Aug 18, 2004 at 09:22 UTC
|
$ sed 1d file
| [reply] [d/l] |
|
$ tail +2 file
| [reply] [d/l] |
Re: perl -pie "???"
by demerphq (Chancellor) on Aug 18, 2004 at 11:49 UTC
|
perl -i.bak -pe "$_='' unless $.>1"
the -i.bak is necessary cause you cant use i without a backup extension on Win32.
---
demerphq
First they ignore you, then they laugh at you, then they fight you, then you win.
-- Gandhi
| [reply] [d/l] |
Re: perl -pie "???"
by Anonymous Monk on Aug 18, 2004 at 11:45 UTC
|
perl -i -pe '${_}x=$.>1' file
| [reply] [d/l] |
Re: perl -pie "???"
by Random_Walk (Prior) on Aug 18, 2004 at 13:23 UTC
|
| [reply] [d/l] |
|
perl -pi -e'$_ x=$.>1'
Doesn't work with multiple files though.
Of course, that has already been posted…
Makeshifts last the longest.
| [reply] [d/l] |