Solved

Switch columns 3 & 4 using perl or shell scripts

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
countPairs challenge 7 58
topping1 challenge 7 53
Perl Write to Specific line in a file 15 52
creating threads in delphi 1 55
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.
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

746 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

11 Experts available now in Live!

Get 1:1 Help Now