Sponsored Content
Full Discussion: Sort references
Top Forums UNIX for Dummies Questions & Answers Sort references Post 302903997 by Don Cragun on Saturday 31st of May 2014 11:40:25 PM
Old 06-01-2014
With well over 800 posts in these forums and the code you have been given, I am disappointed that you could not add reference numbers on your own. Try this minor modification to clx's awk script:
Code:
#!/bin/ksh
# Usage: sortrefs [starting_sequence_number [input_file]]
# Sort references found in the given input_file (default ref.txt) and add
# sequences numbers starting with starting_sequence_number (default 1).
awk '
{	gsub(/\n/,"\1");
	print $0 "\1"
}' RS='' "${2:-ref.txt}" | sort | awk -v sseq="${1:-1}" '
{	gsub(/\1/, "\n")
	printf("[%d] %s\n", sseq++, $0)
}'

As always, if you want to try this on a Solaris/SunOS system, change awk (in both places where it is used in this script) to /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk.

I use the Korn shell, but this script can use, ksh, bash, or any other shell that supports POSIX required variable expansions. If you save the above script in a file names sortrefs, make it executable, and invoke it as:
Code:
./sortrefs 44

when ref.txt contains your sample input, the output produced is:
Code:
[44] Anderson, E.R., Duvall, T.L., Jr., and Jefferies, S.M., 1990. Modelling 
     of Solar Oscilation Power Spectra. The Astrophysical Journal, vol. 364, 
     p. 699.

[45] Basu, S., Antia, H.M., and Tripathy, S.C. 1999. Ring Diagram Analysis
     of Near-Surface Flow in the Sun. The Astrophysical Journal, vol. 512, 
     pp. 458-470.

[46] Duvall, T.L., Jr., and Harvey, J.W., 1986. Solar Doppler Shifts: Sources 
     of Continuous Spectra. In Seismology of the Sun and the Distant Stars, 
     (ed. D. Gough), NATO A Ser., Reidel, Dordrecht, p. 105.

[47] Nigam, R., Kosovichev, A.G., Scherrer, P.H., and Schou, J., 1998. 
     Asymmetry in Velocity and Intensity Helioseismic Spectra: A solution 
     to a long-standing puzzle. The Astrophysical Journal, vol. 495, 
     pp. L115-L118.

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

IRIX books, manuals, references...

Does anyone out there know of ANY specific books pertaining to SGI's flavor of Unix - IRIX? I have been in contact with SGI directly and they have not supplied me with any usable reference material or manuals. I realize man pages are a good source for info, but I need to go a little deeper... (6 Replies)
Discussion started by: lozinit
6 Replies

2. AIX

AIX References?

Would like to know where or what is available to quickly develope my AIX skills. Training budget limited.. Thanks and have a great day! (1 Reply)
Discussion started by: lmwical
1 Replies

3. UNIX for Advanced & Expert Users

Compound indirect variable references

Using bash, I'm trying to read a .properties file (name=value pairs), assigning an indirect variable reference for each line in the file. The trick is that a property's value string may contain the name of a property that occurred earlier in the file, and I want the name of the 1st property to... (5 Replies)
Discussion started by: tkrussel
5 Replies

4. Programming

Wanted: References on Sockets and Threads for C

I'm looking at http://www.opengroup.org/pubs/online/7908799/xsh/pthread.h.html trying to understand mutexs and semaphores. Windows makes a distinction between the two. Is a mutex and semaphore different in unix land? Is there a tutorial on threading in unix somewhere? I'm also looking at... (4 Replies)
Discussion started by: siegfried
4 Replies

5. Shell Programming and Scripting

perl - passing hash references to functions

hi there I have the following script in which i have created a PrintHash() function. I want to pass to this function the reference to a hash (in the final code i will be passing different hashes to this print function hence the need for a function). I am getting an error Type of arg 1 to... (1 Reply)
Discussion started by: hcclnoodles
1 Replies

6. Shell Programming and Scripting

Perl References/Dereferences

Can someone explain where can we actually used print $var->; or print $$var When does the -> becomes necessary and when its optional. (1 Reply)
Discussion started by: dinjo_jo
1 Replies

7. Shell Programming and Scripting

Strip one of two Patch references

This log file is wacky. the syntax puts this in the Installation line: Installation PATCH75682.91 of PATCH75681 complete Installation PATCH76537.91 of PATCH76537 complete Installation PATCH92217.91 of PATCH92217 complete So I'm looking for a sed 's///' to remove the first PATCHxxxx... (6 Replies)
Discussion started by: dba_frog
6 Replies

8. Shell Programming and Scripting

Query related to references in array in Perl

Hi All I have a doubt and want to be cleared I am using @array = (10, 20); $rarray = \@array; #print "$rarray\n"; #print "@$rarray\n"; $rr= \$array; #print $$rr; $rr++; print $$rr; As you can see the $rr contains the reference to the first element of the array , now as the... (5 Replies)
Discussion started by: parthmittal2007
5 Replies

9. Shell Programming and Scripting

awk Programming references

Hi all, I am new and I am very interested in Awk programming language and would like to know what references or books that really worked for you that was clear, concise with simple examples. much appreciated in advance. (1 Reply)
Discussion started by: Apollo
1 Replies
WRAP-AND-SORT(1)                                              General Commands Manual                                             WRAP-AND-SORT(1)

NAME
wrap-and-sort - wrap long lines and sort items in Debian packaging files SYNOPSIS
wrap-and-sort [options] DESCRIPTION
wrap-and-sort wraps the package lists in Debian control files. By default the lists will only split into multiple lines if the entries are longer than 80 characters. wrap-and-sort sorts the package lists in Debian control files and all .install files. Beside that wrap-and-sort removes trailing spaces in these files. This script should be run in the root of a Debian package tree. It searches for control, control.in, copyright, copyright.in, install, and *.install in the debian directory. OPTIONS
-h, --help Show this help message and exit. -a, --wrap-always Wrap all package lists in the Debian control file even if the entries are shorter than 80 characters and could fit in one line line. -s, --short-indent Only indent wrapped lines by one space (default is in-line with the field name). -b, --sort-binary-packages Sort binary package paragraphs by name. -k, --keep-first When sorting binary package paragraphs, leave the first one at the top. Unqualified debhelper(7) configuration files are applied to the first package. -n, --no-cleanup Do not remove trailing whitespaces. -d path, --debian-directory=path Location of the debian directory (default: ./debian). -f file, --file=file Wrap and sort only the specified file. You can specify this parameter multiple times. All supported files will be processed if no files are specified. -v, --verbose Print all files that are touched. AUTHORS
wrap-and-sort and this manpage have been written by Benjamin Drung <bdrung@debian.org>. Both are released under the ISC license. DEBIAN Debian Utilities WRAP-AND-SORT(1)
All times are GMT -4. The time now is 08:54 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy