Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: perl one-liner

by Kanji (Parson)
on Jun 22, 2005 at 17:02 UTC ( #469095=note: print w/replies, xml ) Need Help??

in reply to perl one-liner

perl -0777 -i -nle 'print q{hello}'

...but as others have pointed out, it's much easier to handle this sort of thing with shell redirection.


Replies are listed 'Best First'.
Re^2: perl one-liner
by mojobo (Initiate) on Jun 22, 2005 at 21:22 UTC
    hi guys,
    actually shell redirection is what i have been doing in the past (without perl), but i wanted to have a one-liner that can be called externally. The basic idea is to automate editing a file with different access permissions than the user, via sudo, and not have to chown the file first to the user..
    i can already edit a file if there is content in the file, without using shell redirection, using a perl one-liner like this:
    perl -i -ne 'print unless 1 .. 100; print q{testing} if$.==1' somefile

    of course this doesn't truncate the file, which is what i was interested in attempting..
Re^2: perl one-liner
by mojobo (Initiate) on Jun 22, 2005 at 21:25 UTC
    Hi Kanji, i didn't see your reply when i was posting mine..
    thanks! that's perfect..
    thanks to everyone for their help.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://469095]
[shmem]: karlgoethebier: isn't bike riding a way of fixing lumbago?
[karlgoethebier]: shmem: scheiss technik
[karlgoethebier]: shmem: yes - i f you manage it to get on the bike. and pray if you must stop...
[shmem]: in the french alpes, at the end of a gravel road, we had a beer at a hut - and heard an enduro coming up.
[shmem]: not by the road, but from there below where you wouldn't want to walk.
[shmem]: the biker stopped the machine at the table and took off his helmet.
[shmem]: long white hair, long beard the same, then he proceeded to get off the bike

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2017-06-25 20:06 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (570 votes). Check out past polls.