Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Sed to perl conversion-- flipping lines in a file

by thelenm (Vicar)
on Feb 17, 2004 at 22:35 UTC ( #329778=note: print w/replies, xml ) Need Help??


in reply to Sed to perl conversion-- flipping lines in a file

Just to be tricksy, here's another way to do it (originally by Eugene van der Pijll in the Santa Golf on the Fun With Perl list):

#!/usr/bin/perl -p $\=$_.$\}{

-- Mike

--
XML::Simpler does not require XML::Parser or a SAX parser. It does require File::Slurp.
-- grantm, perldoc XML::Simpler

Replies are listed 'Best First'.
Re: Re: Sed to perl conversion-- flipping lines in a file
by NovMonk (Chaplain) on Feb 19, 2004 at 22:02 UTC
    This is very cool, Mike. I tried to modify it so that it would only flip lines that met certain conditions (like my sed example above) and went down in flames. Is there a way to get this code to Only swap lines around if the lines contain the following text: '1' or '2' or '3' and to otherwise print the lines in the original file order?

    What I really want to get to is something that will convert this highlighted text in vi editor (alas, I am so far in the dark ages my company has not even Heard of Vim, but would probably burn me at the stake for speaking of it):

    Line 1 Line 2 Line 3 flip line '1' flip line '2' flip line '3' Line 4 to: Line 1 Line 2 Line 3 flip line '3' flip line '2' flip line '1' Line 4

    Does this make more sense to anyone?

    Thanks very much for the (hopefully) gentle correction and admonishment, Monks.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://329778]
help
Chatterbox?
[marto]: yeah, the whole infrastructure has changed, and video codecs have moved on a great deal
[Corion]: marto: Redoing something on new infrastructure sounds fun. At least you can reuse your previous experience :)
[marto]: I'm looking forwads to it. The video sources are dying, and they don't have the hardware to play them back (old tape formats, not just VHS + Laserdisc etc)
[marto]: I'll be interested to see what difference in terms of file size/quality the new codecs make. I enjoy working on things like this, so that's a bonus
[Corion]: Ah, cool! So it's not an inhouse youtube but for a wider consumption
[marto]: last time it was IE6 clients, now they're on 11, so more scope there also, in terms of UI and playback

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2017-07-28 09:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (425 votes). Check out past polls.