Sponsored Content
Top Forums Shell Programming and Scripting Sort alphabetically, then numerically Post 302502968 by 1cor29 on Wednesday 9th of March 2011 10:45:32 AM
Old 03-09-2011
Sort alphabetically, then numerically

Greetings - I'm not necessarily new to bash scripting - I'm probably between beginner and intermediate, but I have something that I just cannot figure out after many attempts to find it. I have a file that is merely a list of many files, with their respective paths, and a branch path (ClearCase) that they live on. For instance, here is an example of this file:

Code:
/vobs/vob/path/to/where/the/file/is/foo.txt@@/main/int/dev/9
/vobs/vob/path/to/where/the/file/is/foo.txt@@/main/int/dev/11
/vobs/vob/path/to/where/the/file/is/foo.txt@@/main/int/dev/10

As you can see, there are 3 instances of a file with 3 different versions depicted. Well, I need it sorted to where the end number is in order.
"sort -n" and "sort" doesn't work. The results are:
Code:
/vobs/vob/path/to/where/the/file/is/foo.txt@@/main/int/dev/10
/vobs/vob/path/to/where/the/file/is/foo.txt@@/main/int/dev/11
/vobs/vob/path/to/where/the/file/is/foo.txt@@/main/int/dev/9

I need it to have the result like this:

Code:
/vobs/vob/path/to/where/the/file/is/foo.txt@@/main/int/dev/9
/vobs/vob/path/to/where/the/file/is/foo.txt@@/main/int/dev/10
/vobs/vob/path/to/where/the/file/is/foo.txt@@/main/int/dev/11

How do you do that??? Smilie
Moderator's Comments:
Mod Comment
Please use code tags when posting data and code samples!

Last edited by vgersh99; 03-09-2011 at 11:46 AM.. Reason: code tags, please!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How to sort alphabetically after finding values

I have a list of people in a usage log and need to print the names and phone numbers of people with over 500 logins. I'd also like to display these names alphabetically. I have their total logins set to a variable named total. So far, I have very little in my awk script to do this: FS=":"... (4 Replies)
Discussion started by: doubleminus
4 Replies

2. UNIX for Dummies Questions & Answers

Sort file alphabetically AND numerically

Hi all. I have 2 files like this: f1 A 10 B 80 C 9 f2 A 11 B 700 C 10 What I want is the concatenation of the two files sorted by name (alphabetically) and size (numerically), so the result should be like this: F3 (cat f1 f2 sorted) A 10 A 11 B 80 B 700 (2 Replies)
Discussion started by: mrodrig
2 Replies

3. Shell Programming and Scripting

Numerically sort problem for a long list of file name

I got a long list of file name. My input: data_1.txt data_2.txt data_3.txt data_10.txt data_21.txt data_12.txt data_4.txt My desired output: data_1.txt data_2.txt data_3.txt data_4.txt data_10.txt data_12.txt data_21.txt Does anybody got idea how to archive it? (11 Replies)
Discussion started by: patrick87
11 Replies

4. Shell Programming and Scripting

Sort by numbers, then alphabetically

Hey guys, I have a file that contains the following: 366 K 364 Q 12 UB 7 INC. P 4 Law 2 LAMB 2 High 1 QEG 1 OF 1 LC 1 B As you can see, it's already sorted by numerical order, how do I sort it again, breaking the ties by using the alphabetical order of the second column, but... (2 Replies)
Discussion started by: Andrew9191
2 Replies

5. UNIX for Dummies Questions & Answers

Sort 2 columns numerically

Hi, A basic query. In the example file below, I want to sort by column 1 and then by column 2 numerically. I have tried sort -k2n,1 file1 but while this sorts the columns in the correct order, it does not sort column 2 numerically. Any help would be much appreciated. Also, if you have time to... (3 Replies)
Discussion started by: auburn
3 Replies

6. Shell Programming and Scripting

Sort numerically a non numerical

Hello, I have this sample data: 01 * * * * 01 * * * * 01 * * * * 01 * * * * 01 0 * * * 01 0 * * * 01 0 * * * 01 0 * * * 02 * * * 0 02 * * * 0 02 * * * 6 02 * * * 6 02 0 * * 1 02 0 * * 1 02 0 * * 2 02 0 * * 2 02 0 * * 3 (3 Replies)
Discussion started by: gio001
3 Replies

7. UNIX for Dummies Questions & Answers

[Solved] Reverse the order of a list of file names (but not sort them alphabetically or numerically)

Hello all, I have a list of file names in a text document where each file name consists of 4 letters and 3 numbers (for example MACR119). There are 48 file names in the document (they are not in alphabetical or numerical order). I would like to reorder the list of names so that the 48th name is... (3 Replies)
Discussion started by: MDeBiasse
3 Replies

8. Shell Programming and Scripting

Using awk to sort a file alphabetically

I have a problem with my homework I need to create a shell script using #!bin/awk -f the script will output the file in an alphabetical order only words and after the word is : after that a space then , then it will be numbered each character by which line its been for example CB 92A A... (1 Reply)
Discussion started by: collapse
1 Replies

9. UNIX for Dummies Questions & Answers

Sort alphabetically starting from specified letter

Hi. I'm trying to sort a list of items in a file alphabetically but starting from the letter 'X'. For instance if I had the following file; test.txt Z A T W Y B S X I would like the output to look like; X Y (8 Replies)
Discussion started by: mmab
8 Replies

10. UNIX for Beginners Questions & Answers

How to sort files in directory numerically?

Trying to sort a bunch of files numerically but can't seem to get the command just right. This is in a IBM AIX machine. I have a directory that has... backup.bk1 backup.bk100 backup.bk2 backup.bk200 backup.bk3 backup.bk300 There are a lot more files but this is shortened for the... (5 Replies)
Discussion started by: c3rb3rus
5 Replies
VOBCOPY(1)							   User Manuals 							VOBCOPY(1)

NAME
vobcopy - copy (rip) files from a dvd to the harddisk SYNOPSIS
vobcopy [-b size[bkmg] ] [-e size[bkmg] ] [-f] [-F fast_factor ] [-h] [-i input-dir ] [-l] [-m] [-M][-n title-number ] [-o output-dir ] [-q] [-O single_file(s)_to_rip ] [-t name ] [-v [-v]] [-x] [-I] [-V] [-L logfile-path ] [-1 aux_output_dir1 ] [-2 aux_output_dir2 ] [-3 aux_output_dir3 ] [-4 aux_output_dir4 ] DESCRIPTION
vobcopy copies DVD .vob files to harddisk (thanks to libdvdread) and merges them into file(s) with the name extracted from the DVD. It checks for enough free space on the destination drive and compares the copied size to the size on DVD (in case the size is wrong the files keep the .partial ending ). It should definitely work on linux and now on FreeBSD, OpenBSD, NetBSD, Solaris and MacOSX too! theCSSissue: Due to possible legal issues, vobcopy doesn't include any code to descramble CSS "enhanced" DVDs. CSS is sold by the DVD industry as a "copy protection", though it's more of a "view protection" as it makes DVDs unviewable with unlicensed players. Some people have hacked CSS decryption routines, and one of those is available as a libdvdread counterpart. So if you have such a DVD, have a look at the libdvdread page. If you are positive that it's allowed where you live, you can just install that mentioned library and make decrypted backups of all your DVDs... vobcopy without any options will copy the title with the most chapters into files of 2GB size into the current working directory. OPTIONS
-b, --begin SIZE[bkmg] begins to copy from the specified offset-size. Modifiers like b for 512-bytes, k for kilo-bytes, m for mega- and g for giga-bytes can be appended to the number. Example: vobcopy -b 500m will start to copy from 500MB onward till the end. -e, --end SIZE[bkmg] similar to -b, this options lets you specify some size to stop before the end. -f, --force force the output to the specified directory even if vobcopy thinks there is not enough free space -F, --fast fast_factor speed up the copying (experimental). fast_factor is in the range 1 to 64 -h, --help print the command line options available -i, --input-dir INPUT-DIR provide vobcopy with the path to the mounted dvd drive -l, --large-file write data into one file (needs large file support (LFS)) -M, --longest choose the title with the longest playing time. With some DVDs this gets the main title better than the most chapter method, with others it's worse. -m, --mirror mirrors the whole dvd to harddisk. It will create a directory named after the dvd and copy the ifo, bup and vob files there. The title-vobs are decrypted during this. -n, --title-number TITLE-NUMBER specify which title vobcopy shall copy (default is title with most chapters). On the dvd, vts_01_x.vob specify the first title (mostly this is the main feature). -o, --output-dir OUTPUT-DIR specify the output-directory of the data. "stdout" or "-" redirect to stdout. Useful for pipeing it to /dev/null ;-) If you forget to pipe it to some place, your terminal will get garbled, so remember that typing "reset" and then Enter will rescue you. -q, --quiet all info- and error-messages of vobcopy will end up in the current directory in vobcopy.bla instead of stderr -O, --onefile single_file(s)_to_rip specify which single file(s) to rip. Parts of names can be given and all files which include the part will be copied. Files can be listed with comma separation. Example: -O video_ts.vob,bup will copy the single file video_ts.vob and all files containing bup -t, --name NAME you can give the file a name if you don't like the one from dvd. -t hallo will result in hallo.vob. (stdout or "-" are deprecated now) If you want to give it names like "Huh I like this movie", do it in quotation marks. -v, --verbose prints more information about whats going on (more verbose). -v -v prints the information given on command line into a log-file in the current directory for inclusion into a bugreport. -x overwrite all existing files without further questions. -L LOGFILE-PATH tells vobcopy where to put the logfile instead of the default. -I, --info prints information about the titles, chapters and angles on the dvd. -V, --version prints version number. -1, --1st_alt_output_dir AUXILIARY-OUTPUT-DIR1 if the data doesn't fit on the first output-directory (specified behind -o) writing will continue here (and after -2 there and -3 and -4) -> the files will be split according to the remaining free space (try specifying the path _directly_ behind -1, _no_ space in between if you have troubles, this might be even necessary at -o...) BUGS
Vobcopy is still under development. So expect some. There *might* be problems for users who's system is not large-file ready. If so, please get back to me. AUTHOR
Robos <robos@muon.de> Linux Jun 2009 VOBCOPY(1)
All times are GMT -4. The time now is 07:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy