LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-10-2014, 07:09 AM   #1
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 258

Rep: Reputation: Disabled
Sort problem


I am trying to sort the iptables output and am not getting the results I want. I am trying to sort by ip addresses.

iptables -L -n -v --line-numbers | sort -n --key=53,55

My results:

10 15 608 DROP all -- * * 220.???.0.0/16 0.0.0.0/0
11 0 0 DROP all -- * * 173..???..120.242 0.0.0.0/0
12 2 104 DROP all -- * * 69..???..33.173 0.0.0.0/0
13 0 0 DROP all -- * * 202..???..54.8 0.0.0.0/0

The IPs are not sorting. It seems that the whole line is sorting.
 
Old 06-10-2014, 07:22 AM   #2
dayid
Member
 
Registered: Apr 2012
Location: Austin, TX
Posts: 44

Rep: Reputation: Disabled
What are you actually trying to accomplish by doing this? This is a case of the X/Y Problem. By knowing what you're actually trying to accomplish (overall) you are more likely to get the correct help.
 
Old 06-10-2014, 07:28 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,137

Rep: Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122Reputation: 4122
First off, things would be a whole lot easier (for us) if you used [code] tags - like this
Code:
10      15   608 DROP       all  --  *      *       220.???.0.0/16       0.0.0.0/0
11       0     0 DROP       all  --  *      *       173..???..120.242    0.0.0.0/0
12       2   104 DROP       all  --  *      *       69..???..33.173      0.0.0.0/0
13       0     0 DROP       all  --  *      *       202..???..54.8       0.0.0.0/0
Next, you'd better read the manpage for a definition of KEYDEF (and --field-separator). That might help you understand what's happening with your attempt. As it happens, if you get "k" right, looks like it should be plain sailing.
 
Old 06-10-2014, 07:49 AM   #4
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 258

Original Poster
Rep: Reputation: Disabled
Just discovered that you are dealing with columns, not data positions. This works.

iptables -L -n -v --line-numbers | sort -n -k9
 
  


Reply



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
Is there a sort of 2nd SSH daemon server, sort of JAILKIT, in the debian repositories frenchn00b Debian 5 06-20-2010 04:03 AM
Can I use GNU sort to sort one field in order, another in reverse? zombieite Linux - Newbie 4 04-27-2009 12:23 AM
php sort help - sort numerical descending then by alphabetical? RavenLX Programming 3 03-11-2009 08:35 AM
selection sort compiles but does not sort the array as desired ganesha Programming 2 04-20-2008 07:44 AM
Is there a line limit with the sort utility? Trying to sort 130 million lines of text gruffy Linux - General 4 08-10-2006 08:40 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:49 AM.

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