LinuxQuestions.org
Register a domain and help support LQ
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, 08:09 AM   #1
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 231

Rep: Reputation: 5
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, 08: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, 08:28 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,839

Rep: Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822Reputation: 1822
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, 08:49 AM   #4
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 231

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

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


Reply


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


All times are GMT -5. The time now is 09:21 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration