Solved

reverse last two columns using perl or shell

Posted on 2011-09-22
6
309 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
Comment Utility
What have you tried?
0
 

Author Comment

by:libertyforall2
Comment Utility
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 11

Expert Comment

by:tel2
Comment Utility
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 11

Expert Comment

by:tel2
Comment Utility
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 11

Accepted Solution

by:
tel2 earned 450 total points
Comment Utility
Alternatively:
    perl -pe 's/(.*) (\S+) (\S+)/$1 $3 $2/' infile.txt >outfile.txt
0
 

Author Closing Comment

by:libertyforall2
Comment Utility
I used the last one. It works great!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Read about achieving the basic levels of HRIS security in the workplace.
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…
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…

743 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

8 Experts available now in Live!

Get 1:1 Help Now