Solved

reverse last two columns using perl or shell

Posted on 2011-09-22
6
313 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
  • 3
  • 2
6 Comments
 
LVL 28

Assisted Solution

by:FishMonger
FishMonger earned 50 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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 450 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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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…
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…

792 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