Solved

Switch columns 3 & 4 using perl or shell scripts

Posted on 2011-02-10
3
421 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
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Utilizing an array to gracefully append to a list of EmailAddresses
This is about my first experience with programming Arduino.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

816 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now