Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Linux - Kernel This forum is for all discussion relating to the Linux kernel.


  Search this Thread
Old 06-21-2014, 03:42 AM   #1
LQ Newbie
Registered: Jun 2014
Posts: 1

Rep: Reputation: Disabled
Question Simplifying single-line command with cut & paste

I have a file "data" with the following text:
1425 Juan 14.25
4321 George 21.11
6781 Anna 16.77
1451 Ben 21.77
2277 Tuan 18.77
In order to swap column 2 and 3, I did this single-line command:
$cut -f1 data > field1 && cut -f2 data > field2 && cut -f4 data > field4 && paste -d" " field1 field4 field2 > output
I was wondering how to simplify that line in any way.
Old 06-21-2014, 10:39 AM   #2
Senior Member
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 491Reputation: 491Reputation: 491Reputation: 491Reputation: 491
You can use awk
awk '{print $1" "$3" "$2}' data


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] is there a command for cut and paste? cristi92b Linux - Newbie 8 06-14-2011 03:57 PM
fixing cut & paste Skaperen Linux - Desktop 3 12-21-2010 04:08 PM
Cut and paste from command line dulli1 Linux - Newbie 9 10-12-2010 09:31 PM
Cut & Paste Rick069 Linux - General 1 04-15-2005 04:58 PM
Cut & paste to browser fend88 Linux From Scratch 2 04-27-2002 09:46 PM > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 08:38 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration