LinuxQuestions.org
Help answer threads with 0 replies.
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 04-12-2013, 08: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, 09:56 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
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, 10:09 AM   #3
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,779

Rep: Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212Reputation: 2212
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, 10: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, 08:31 AM   #5
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
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, 07: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



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 05:26 PM
LFS6.3 - Ch5.4.1 "/bin/sh sort not found" error at "make bootstrap" ubyt3m3 Linux From Scratch 2 06-23-2008 12:09 AM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
bash Problem with "sed" command blubbfish Linux - Newbie 3 06-01-2004 10:14 AM
Bash Script: Problem running variable command containing "" Paasan Programming 2 01-21-2004 01:45 AM

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

All times are GMT -5. The time now is 06:03 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
Open Source Consulting | Domain Registration