Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageAbhishek 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.
Post Follow-up to this messageOn 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
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.