LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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 04-12-2013, 09:13 AM   #1
rt1870
LQ Newbie
 
Registered: Apr 2013
Posts: 2

Rep: Reputation: Disabled
Bash "sort" command problem


I am trying to use a piece of scientific software that involves executing a number of scripts and commands.There is a particular step I am stuck on, where the program needs a file to be sorted and the documentation gives the command:

sort +3 -25 file1 >file2

The options +3 and -25 do not seem to correspond to any of the options for "sort" when I look at the help in bash. Am I missing something simple here? Is this not actually a bash command and something else? Unfortunately the documentation does not explain the way in which the data needs to be sorted, so I am unable to implement my own solution.

I am fairly new to using bash and linux in general and am completely stuck. Any help appreciated!
 
Old 04-12-2013, 10:56 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Jessie 8.4
Posts: 5,873

Rep: Reputation: 348Reputation: 348Reputation: 348Reputation: 348
Quote:
I am trying to use a piece of scientific software that involves executing a number of scripts and commands.There is a particular step I am stuck on, where the program needs a file to be sorted and the documentation gives the command:

sort +3 -25 file1 >file2
It would help if you identified that "scientific software" so that others can examine the documentation.
 
Old 04-12-2013, 11:09 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 2,957

Rep: Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267Reputation: 1267
sort is a separate program and not something internal to bash. The command line you were given uses an obsolete syntax, and specifies a sort beginning with field 3 and extending up to but not including field 25, where the fields are numbered from 0. The current manual page for sort no longer describes this syntax, though the sort command itself does still accept it. You can find a page that includes the obsolete syntax here.

The modern equivalent would be
Code:
sort -k4,25 file1 >file2
The field numbers here start from 1, and the sort is inclusive of the starting and ending field numbers.
 
1 members found this post helpful.
Old 04-12-2013, 11:12 AM   #4
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
I think they are key field numbers and are somehow similar to the values presented with -k only that the position is n + 1. e.g. sort +3 -25 is similar to sort -k4,25. The numbers presented in -k represent the key fields of the line which are prioritized in sorting before the whole line is sorted in general.

So if I have a file containing
Code:
aaa	def	ghi
bbb	abc	ghi
aaa	abc	jkl
Code:
sort +1 -3 file.txt
sort -k 2,3 file.txt
sort -k 2 file.txt
will have
Code:
bbb     abc     ghi
aaa     abc     jkl
aaa     def     ghi
and
Code:
sort +1 -2 file.txt
sort -k 2,2 file.txt
will have
Code:
aaa     abc     jkl
bbb     abc     ghi
aaa     def     ghi
 
2 members found this post helpful.
Old 04-14-2013, 09:31 AM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Try reading "info sort". It describes the usage of the program in a lot more detail than the manpage.

This is true of most info pages, by the way.
 
1 members found this post helpful.
Old 04-17-2013, 08:12 AM   #6
rt1870
LQ Newbie
 
Registered: Apr 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
Just a bump to say thank you to the replies - answered my question perfectly (especially konsolebox!).
 
  


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
[SOLVED] sort command output differs when encounters "-" (hyphen) kushalkoolwal Programming 6 03-18-2010 06:26 PM
LFS6.3 - Ch5.4.1 "/bin/sh sort not found" error at "make bootstrap" ubyt3m3 Linux From Scratch 2 06-23-2008 01:09 AM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 11:18 PM
bash Problem with "sed" command blubbfish Linux - Newbie 3 06-01-2004 11:14 AM
Bash Script: Problem running variable command containing "" Paasan Programming 2 01-21-2004 02:45 AM


All times are GMT -5. The time now is 06:24 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