[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

reverse last two columns using perl or shell

Posted on 2011-09-22
6
Medium Priority
?
319 Views
Last Modified: 2012-06-22
I have the attached file. I want to do 2 things. 1. reverse the last two columns & 3 round all values in the last two columns to the nearest hundredth. A sample file is attached.
so4pap.txt
0
Comment
Question by:libertyforall2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 28

Assisted Solution

by:FishMonger
FishMonger earned 200 total points
ID: 36584932
What have you tried?
0
 

Author Comment

by:libertyforall2
ID: 36584993
I've tried importing it into excel then saving as a text file after I switch columns. It leaves gaps between columns for certain rows and does work correctly. I simply want to switch the last two columns. uhggg.
0
 
LVL 12

Expert Comment

by:tel2
ID: 36585229
Hi lfa2,

To put output in a 2nd file:
    perl -lane 'print "$F[0] $F[1] $F[3] $F[2]"' infile.txt >outfile.txt

To modify the input file:
    perl -i -lane 'print "$F[0] $F[1] $F[3] $F[2]"' infile.txt
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:tel2
ID: 36585239
Or more concisely:
    perl -lane 'print "@F[0,1,3,2]"' infile.txt >outfile.txt
or:
    perl -i -lane 'print "@F[0,1,3,2]"' infile.txt
0
 
LVL 12

Accepted Solution

by:
tel2 earned 1800 total points
ID: 36590939
Alternatively:
    perl -pe 's/(.*) (\S+) (\S+)/$1 $3 $2/' infile.txt >outfile.txt
0
 

Author Closing Comment

by:libertyforall2
ID: 36593052
I used the last one. It works great!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question