Say that I had a list of entries in a text file:
- Apple/bcd
- Pear/abc
- banana/def
- orange/cde
and I wanted to sort these entries in the console by what comes after the "/" so they were:
- Pear/abc
- Apple/bcd
- orange/cde
- banana/def
How do I use the sort function to sort this way without having columns there?
And by only using the sort function, no piping other commands?
I can only sort by the word before the "/".
1 Answer
Try this:
sort -t / -k 2,2 _file_ The -t / says the field separator is the / character. The -k 2,2 says to sort on field 2, which would be the characters after the first /.