Solved

Switch columns 3 & 4 using perl or shell scripts

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

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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 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