2

I want to sort file, by the first number, which looks like this.

11: wc 1:cmp: 115:wc 7:ls 

So i get output in file like this.

1:cmp: 7:ls 11: wc 115:wc 

I've tried to sort it my self, but it doesn't work. This is my following code

cat dat | sort -t ":" -k 1 >dat; 

What can i do? Thank you!

2 Answers 2

2

You can use this sort command with numeric sort:

sort -t: -nk1 file 1:cmp: 7:ls 11: wc 115:wc 
Sign up to request clarification or add additional context in comments.

2 Comments

thank you it works! i used it like: cat $dat | sort -t: -nk1 >dat;
yes i just did. i couldn't do it before because you must wait like 5 min to mark it.
0

For the sort part you can do

$ cat dat | sort -t: -k1,1n 1:cmp: 7:ls 11: wc 115:wc 

But if you want to save the sorted lines to dat file again you should do

$ cat dat | sort -t: -k1,1n > dat_copy $ cp dat_copy dat $ rm dat_copy 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.