Review your favorite Linux distribution.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 05-17-2005, 08:33 AM   #1
Senior Member
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 52
simple bash question about cut

I want to print 2 fields according to a delemeter but I want to change the order.

With cut the -f5,1 and -f1,5 print the same thing.
first the first field and then the 5th field.
I need the 5th fiend displayed first, in order to sort the file according to this field.
Is there an easy way, or do I have to use awk,perl and those kind of stuff.
Thanx, for any help
Old 05-17-2005, 10:31 AM   #2
Senior Member
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 59
Without searching a whole lot, I didn't find anything on cut but awk does it very nicely...
cat file.txt | awk '{print$5,$1}'

While we are at it, here is what sort may look like...

awk '{print $0}' | sort -k 5 -nr file.txt > file1.txt
sort -k 5 -nr file.txt > file1.txt

Last edited by homey; 05-17-2005 at 10:36 AM.
Old 05-17-2005, 11:25 AM   #3
Senior Member
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Original Poster
Rep: Reputation: 52
I asked a guy next door (I'm in a Univercity) and he told me about: awk '{print$5,$1}' , long before you posted your reply, but really thanks for replying.
I guess knowing bash without knowing sed and awk is not good....
I think I can use a good awk tutorial.


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
very simple bash programming question!? Thinking Programming 7 06-01-2005 11:07 AM
Simple Bash Question sio Programming 6 11-22-2004 09:56 AM
simple bash script question bullium Programming 3 11-01-2004 02:42 PM
Bash Scripting--Simple Question mooreted Linux - General 4 05-10-2004 01:44 PM
Simple bash question pk21 Programming 2 12-01-2002 05:06 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:45 AM.

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