"Help" Sorting using filename only without considering the path


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting "Help" Sorting using filename only without considering the path
# 8  
Old 05-12-2011
Quote:
Originally Posted by ctsgnb
ok it looks like your sort doesn't have the -k option nor the -t option ...
so try this :

Code:
sed 's:\(.*/\)\(.*\):\2 \1\2:' mylist.txt | sort | sed 's:.* ::'

or this
Code:
sed 's:\(.*/\)\([^/]*\):\2 \1\2:' mylist.txt | sort | sed 's:[^/]* ::'

Both of those are working fine; I am guessing that it might be more efficient than using the while loop ???? not really sure I will have to experiment.

Thanks again I have many ways to choose to do this now.
# 9  
Old 05-12-2011
@snapppy46 Thank you for your kind acknowledgement. I have come unstuck with Busybox before and I can't test solutions in any of my environments. There are experts around who react to "Busybox" in the title of the post. It is a very common Operating System in embedded systems.
(Quietly Flips channel with remote control blissfully unaware of what makes it work).
# 10  
Old 05-12-2011
you can also try

Code:
awk -F/ '{print $NF":"$0}' mylist.txt | sort | cut -d: -f2

and ... by the way ,
If you stick with the while loop, you may want to use
Code:
filename2=${filename##*/}

rather than
Code:
filename2=`basename "${filename}"`


Last edited by ctsgnb; 05-12-2011 at 06:56 PM.. Reason: Ooops i forgot to double the hash ... fixed !
# 11  
Old 05-12-2011
You guy's are the best this work very good and is very fast: sed 's:\(.*/\)\(.*\):\2 \1\2:' mylist.txt | sort | sed 's:.* ::'Unfortunately I forgot one detail; I would like the sort to be case insensitive and -f does not exist in this version of sort. I really hate to be a pain about this but anything I could do to make this happen.

Sorry for not thinking about that earlier but I only notice it when I looked at the output created by my script.

Thanks

@methyl; thanks for the advice next time I will make sure that busybox is included in the thread title.
# 12  
Old 05-13-2011
Code:
awk -F/ '{print tolower($NF)":"$0}' mylist.txt | sort | cut -d: -f2

# 13  
Old 05-18-2011
Thank you for all your replies. Things are working just the way I want due to your contributions.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. Shell Programming and Scripting

find . -path "*_nobackup*" -prune -iname "*.PDF" \( ! -name "*_nobackup.*" \)

These three finds worked as expected: $ find . -iname "*.PDF" $ find . -iname "*.PDF" \( ! -name "*_nobackup.*" \) $ find . -path "*_nobackup*" -prune -iname "*.PDF" They all returned the match: ./folder/file.pdf :b: This find returned no matches: $ find . -path "*_nobackup*" -prune... (3 Replies)
Discussion started by: wolfv
3 Replies

4. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

5. Shell Programming and Scripting

"find . -printf" without prepended "." path? Getting path to current working directory?

If I enter (simplified): find . -printf "%p\n" then all files in the output are prepended by a "." like ./local/share/test23.log How can achieve that a.) the leading "./" is omitted and/or b.) the full path to the current directory is inserted (enclosed by brackets and a blank)... (1 Reply)
Discussion started by: pstein
1 Replies

6. UNIX for Dummies Questions & Answers

"tail -n 1 filename" error while "head -n 1 filename" is ok?

Hi all, I was wondering why tail -n 2 filename produce an error when I manage to do similar command on head -n 2 filename SunOS{type8code0}: tail -n 2 filename usage: tail ] tail ] (2 Replies)
Discussion started by: type8code0
2 Replies

7. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

8. UNIX for Dummies Questions & Answers

the meaning of "!:*" in "alias foo 'command\!:*' filename"

Hi: How can I remove my own post? Thanks. (2 Replies)
Discussion started by: phil518
2 Replies

9. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies
Login or Register to Ask a Question