Solved

Switch columns 3 & 4 using perl or shell scripts

Posted on 2011-02-10
3
430 Views
Last Modified: 2012-05-11
If I have a file that looks like this. The date may also be 01/01/11 format and column 3 & 4 may contain whole numbers as well like 2, 3, 4 rounded to the whole number. How would I switch column 3 & 4 while leaving everything else alone?

01-24-2011 14:15:01 0.00 0.00
01-25-2011 02:15:02 0.00 0.00
01-25-2011 14:15:02 0.00 0.00
01-26-2011 02:15:02 0.00 0.00
01-26-2011 14:15:01 0.00 0.00
01-27-2011 02:15:01 0.00 0.00
01-27-2011 14:15:01 0.00 0.00
01-28-2011 02:15:01 0.00 0.00
01-28-2011 14:15:01 0.00 0.00
01-29-2011 02:15:01 0.00 0.00
01-29-2011 14:15:01 0.00 0.00
01-30-2011 02:15:01 0.01 0.00
01-30-2011 14:15:01 0.01 0.01
01-31-2011 02:15:01 0.00 0.00
01-31-2011 14:15:01 0.00 0.00
02-01-2011 02:15:01 0.00 0.00
02-01-2011 14:15:01 0.00 0.00
02-02-2011 02:15:01 0.00 0.00
02-02-2011 14:15:01 0.00 0.00
02-03-2011 02:15:01 0.00 0.00
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 Comments
 
LVL 9

Accepted Solution

by:
sshah254 earned 250 total points
ID: 34867770
In perl, read the line, use the split function (split at spaces) to split the line into array.  Print the line back
with elements 2 & 3 reversed (elements will be 0, 1, 2, and 3 ... 4 elements).

Ss
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 250 total points
ID: 34867781
perl -lane 'print "@F[0,1,3,2]"'
0
 

Author Closing Comment

by:libertyforall2
ID: 34868346
works great!
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

729 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