From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Doug Lewan Newsgroups: gmane.emacs.help Subject: RE: Sorting lines by length Date: Tue, 16 Sep 2014 13:48:51 +0000 Message-ID: <155DEC68569B714B86C2C7075F5EDA9892B1F74F@DAKIYA1.pegasus.local> References: <87k353zptq.fsf@hornfels.zedat.fu-berlin.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1410875421 15236 80.91.229.3 (16 Sep 2014 13:50:21 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 16 Sep 2014 13:50:21 +0000 (UTC) To: Loris Bennett , "help-gnu-emacs@gnu.org" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Sep 16 15:50:14 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1XTt8z-0000oJ-DT for geh-help-gnu-emacs@m.gmane.org; Tue, 16 Sep 2014 15:50:09 +0200 Original-Received: from localhost ([::1]:38115 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTt8z-0007nS-1N for geh-help-gnu-emacs@m.gmane.org; Tue, 16 Sep 2014 09:50:09 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44043) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTt7t-0006ei-Rw for help-gnu-emacs@gnu.org; Tue, 16 Sep 2014 09:49:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XTt7m-0004Sr-K4 for help-gnu-emacs@gnu.org; Tue, 16 Sep 2014 09:49:01 -0400 Original-Received: from webmail.shubertorg.com ([207.246.209.200]:48386) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTt7m-0004SK-GT for help-gnu-emacs@gnu.org; Tue, 16 Sep 2014 09:48:54 -0400 Original-Received: from dakiya1.pegasus.local ([172.16.208.201]) by DAKIYA1.pegasus.local ([172.16.208.201]) with mapi id 14.02.0247.003; Tue, 16 Sep 2014 09:48:52 -0400 Thread-Topic: Sorting lines by length Thread-Index: AQHP0a4123/rBgOiZUKkmKYWImRYbZwDxWFQ In-Reply-To: <87k353zptq.fsf@hornfels.zedat.fu-berlin.de> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.0.21.202] X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 X-Received-From: 207.246.209.200 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:99954 Archived-At: The code for (sort-lines) looks simple enough. Look at the definition of (s= ort-subr) (the last line of the definition of (sort-lines) in emacs 24.3). = You could use something like the following for a predicate: (defun compare-lengths (left right) "Return non-nil if the string LEFT is shorter than the RIGHT." (< (length left) (length right))) ,Doug Douglas Lewan Shubert Ticketing (201) 489-8600 ext 224 or ext 4335 "This is a slow pup," he said continuing his ascent. > -----Original Message----- > From: help-gnu-emacs-bounces+dougl=3Dshubertticketing.com@gnu.org > [mailto:help-gnu-emacs-bounces+dougl=3Dshubertticketing.com@gnu.org] On > Behalf Of Loris Bennett > Sent: Tuesday, 2014 September 16 08:57 > To: help-gnu-emacs@gnu.org > Subject: Sorting lines by length >=20 > Hi, >=20 > Is there a canonical way of sorting lines by length, longest first? >=20 > I have a file with which might look like this: >=20 > 7-Jan-2013 node025 node061 > 14-Jan-2013 node025 node034 node061 > 21-Jan-2013 node025 node034 node050 node061 > 28-Jan-2013 node025 node034 node061 > 4-Feb-2013 node025 node034 node061 > 11-Feb-2013 node025 node034 node061 > 18-Feb-2013 node034 > 25-Feb-2013 node034 > 11-Mar-2013 node025 >=20 > I actually just need the longest line first. For the example above > this > is quite easy to see, but in the real file, there are around 100 lines > and the longest might have around 1000 characters. >=20 > My use case is reading the data into an R data frame. The number of > columns in the resulting data frame seems to be determined by the > number > of items in the first line. >=20 > Cheers, >=20 > Loris >=20 > -- > This signature is currently under construction.