Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

regexp help
Hello ,

i am sticking with a problem to replace all words of a file in such a =
manner that the first and second word need to interchanged.
some thing like ...

100000 100001 20000 20001 ....



so that the output file will be

100001 10000 20001 20000 ....



any helpful regex  ???

thanks





Report this thread to moderator Post Follow-up to this message
Old Post
Abhishek Dave
03-29-05 01:56 AM


Re: regexp help
Abhishek Dave schreef:
> Hello ,
>
> i am sticking with a problem to replace all words of a file in such a =
> manner that the first and second word need to interchanged.
> some thing like ...
>
> 100000 100001 20000 20001 ....
>
>
>
> so that the output file will be
>
> 100001 10000 20001 20000 ....
>
>
>
> any helpful regex  ???

Just a try, untested:

s/^\s*(.*?)\s(.*?)/$2 $1/

Not sure the ? in *? are necessary though.

HTH, H.


Report this thread to moderator Post Follow-up to this message
Old Post
Hendrik Maryns
03-29-05 01:56 AM


Re: regexp help
On Mar 28, Abhishek Dave said:

> i am sticking with a problem to replace all words of a file in such a =
> manner that the first and second word need to interchanged.
> some thing like ...
>
> 100000 100001 20000 20001 ....
>
> so that the output file will be
>
> 100001 10000 20001 20000 ....

The easiest way I can think of is:

s/(\S+)(\s+)(\S+)/$3$2$1/g;

That reverses every pair of fields, and retains the whitespace that was
between them.

--
Jeff "japhy" Pinyan         %  How can we ever be the sold short or
RPI Acacia Brother #734     %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %    -- Meister Eckhart

Report this thread to moderator Post Follow-up to this message
Old Post
Jeff 'japhy' Pinyan
03-29-05 01:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:52 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.