Issues with sort and forward slash


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Issues with sort and forward slash
# 1  
Old 09-04-2013
Issues with sort and forward slash

I have some directories I am trying to sort. When I attempt to sort them and they are in this format, everything works great:

Code:
file
/vol/trees10
/vol/trees2
/vol/trees7

Code:
cat file |sort -ts -k2 -n

Code:
/vol/trees2
/vol/trees7
/vol/trees10

This makes thefiles in the order
Code:
/vol/trees2
/vol/trees7
/vol/trees10

However, if I try to do use a forward slash as the delimiter: sort -t/ it does not work. I've tried sort -t "/" and tried using -k. This is probably an easy question, but I'm just missing something.
# 2  
Old 09-04-2013
Quote:
Originally Posted by newbie2010
...
However, if I try to do use a forward slash as the delimiter: sort -t/ it does not work. I've tried sort -t "/" and tried using -k. This is probably an easy question, but I'm just missing something.
That looked correct to me, and I've just tried this on linux - worked fine.
For your example, you'd want:
Code:
sort -t '/' -k 3

What commandline are you trying?
# 3  
Old 09-05-2013
Still can't get it working

I am using bash on a Solaris system. I still haven't gotten the command to work. The minute I try the forward slash as a delimiter, the command does not work even if I use -kn for numerical order.
# 4  
Old 09-05-2013
Quote:
Originally Posted by newbie2010
I am using bash on a Solaris system.
hmm...

You do use the binaries in "/usr/xpg4/bin", not in /usr/bin", don't you?

I hope this helps.

bakunin
# 5  
Old 09-05-2013
Still can't get it to work

I've tried the binaries in /usr/xpg4/bin/ and I don't think it makes a difference. I still cannot sort this list. The only way I can sort the list is if use "s" as a delimiter. "/" does not seem to work at all. I have also tried a Linux system with the same issue. Also, I have tried the following:

Code:
[sort -t '/' -k 3,3n
sort -t '/' -k 2,2n

I then tried a 2.6n to attempt to use characters in the sorting. I tried what other folks have recommended in their posts but no luck. Anyone have any clues?

So far this is the only command that works:

Code:
cat file |sort -ts -k2 -n

If I use it I get the list in the desired order:

Code:
/vol/trees2
/vol/trees7
/vol/trees10


Otherwise I get:

Code:
/vol/trees10
/vol/trees2
/vol/trees7

---------- Post updated at 09:43 AM ---------- Previous update was at 09:02 AM ----------

I saw another post on a forum where someone was having issues with the tab key:

Unix sort on multiple fields

I am not sure if this is a similar issue. Has anyone had to escape the forward slash or is there a way to find the version of the sort command?
# 6  
Old 09-05-2013
I think the syntax is -t/ not -t /
# 7  
Old 09-05-2013
Quote:
Originally Posted by newbie2010
I saw another post on a forum where someone was having issues with the tab key:

Unix sort on multiple fields

I am not sure if this is a similar issue. Has anyone had to escape the forward slash or is there a way to find the version of the sort command?
No need to escape the forward slash but specify the exact location of the numerical column...and if the input file has all entries with the last column being of the form "trees[0-9]+" then the following sort should work on all platforms...
Code:
sort -t / -k3.6n file

And if the length of the string literal varies then you'd have to do more processing before it can be sorted...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Escaping Forward Slash

./split2.sh: line 1: split/ssl/pop3s.txt: No such file or directory sort: cannot read: split/ssl/pop3s.txt: No such file or directory Hi there, I am pulling data from the following source: ssl/http ssl/http ssl/http-alt ssl/https ssl/https ssl/https ssl/https ssl/https ssl/https... (3 Replies)
Discussion started by: alvinoo
3 Replies

2. UNIX for Beginners Questions & Answers

Using forward slash in search pattern in perl script

I have existing pattern in the perl script as: my $pattern = "^Line.*?:|^Errors*: |^SEVERE:.*?:|^Null pointer exception occurred"; and I wanted to include below keywords in my search pattern "I/O exception" and "FileNotFoundException"the problem is when I include my pattern like my... (5 Replies)
Discussion started by: ambarginni
5 Replies

3. UNIX for Dummies Questions & Answers

Awk pattern with letters and forward slash

Hi, I have a tab delimited file "test.txt" like this: id1 342 C/T id2 7453 T/A/-/G/C id3 531 T/C id4 756 A/T/G id5 23 A/G id6 717 T/A/C id7 718 C/T/A And so on, with the possible choices for letters being A,C,T,G. I would like to exclude from my file all the lines that do not have... (3 Replies)
Discussion started by: francy.casa
3 Replies

4. Shell Programming and Scripting

AWK or SED to replace forward slash

hi hope somebody can help, there seems to be bit on the net about this, but still cant make it work the way i need. i have a file live this mm dd ff /dev/name1 mm dd ff /dev/name2 mm dd ff /dev/name3 mm dd ff /dev/name4 i need to update /dev/name1 etc to /newdev/new/name1 etc so... (5 Replies)
Discussion started by: dshakey
5 Replies

5. UNIX for Dummies Questions & Answers

Replace Forward Slash with sed

i need to replace '/' forward slash with \/(backward slash follwed by a forward slash) using sed command when the forward slash occurs as a first character in a file.. Tried something like this but doesn't seem to work. find $1 -print0 | xargs -0 sed -i -e 's/^\//\\\//g' Can someone... (19 Replies)
Discussion started by: depakjan
19 Replies

6. Shell Programming and Scripting

Significance of forward slash(/) while specifying a directory

What is the significance of the forward slash(/) while specifying a directory? cp -av /dir/ /opt/ and cp -av /dir /opt Does effectively the same job it seems? (2 Replies)
Discussion started by: proactiveaditya
2 Replies

7. Shell Programming and Scripting

Using sed to append backward slash before forward slash

Hi all, I need to know way of inserting backward slash before forward slash. My problem is that i need to supply directory path as an argument while invoking cshell script. This argument is further used in script (i.e. sed is used to insert this path in some file). So i need to place \ in front... (2 Replies)
Discussion started by: sarbjit
2 Replies

8. Shell Programming and Scripting

escaping / (forward slash)

how to escape / (forward slash) in a string. I have following scnerio: sed s/${var1}{$var2} var1 and var2 both contain slashes, but sed gives error if there is a slash in var1 or var2. sed is used here to replace var1 with var2. Thanks in advance (1 Reply)
Discussion started by: farooqpervaiz
1 Replies

9. Shell Programming and Scripting

Help with SED and forward slash

Using the script: (Called replaceit) #!/bin/ksh String=$1 Replace=$2 sed -e "s/${orig}/${new}/g" oldfile.txt > newfile.txt In oldfile.txt, I'm looking for: getenv("Work") And change it To: /u/web I execute the script: replaceit "getenv(\""Work\"")" /u/web I'm getting sed... (3 Replies)
Discussion started by: gseyforth
3 Replies

10. Shell Programming and Scripting

grep for forward slash

How can I use grep to grab a line that contains a forward slash? I've tried: grep "/pd " file, Inevitably it just grabs pd not /pd. (3 Replies)
Discussion started by: wxornot
3 Replies
Login or Register to Ask a Question