2

I have a file in which there are numbers like

6.3.0.00.220
6.3.0.00.220C
6.3.0.00.220EH
6.3.0.00.221
6.3.0.00.221C
6.3.0.00.221EH

and so on

I want them to be groped/sorted as

6.3.0.00.220EH
6.3.0.00.221EH
6.3.0.00.220C
6.3.0.00.221C
6.3.0.00.220
6.3.0.00.221

Basically EH ones together in ascending then C together in ascending and then the rest in ascending.

I am trying sort -k 1.10,1.14 -nr | sort -k 1.13 -r but not getting the exact output.

2 Answers 2

3

Will this work for you sort -r -t. -k5.4 -s somefile.txt

Sign up to request clarification or add additional context in comments.

1 Comment

1

Test file:

$ cat test.txt 
6.3.0.00.220
6.3.0.00.220C
6.3.0.00.220EH
6.3.0.00.221
6.3.0.00.221C
6.3.0.00.221EH

Running a command:

$ cat <(grep -E -e "EH$" test.txt | sort) \
      <(grep -E -e "C$" test.txt | sort) \
      <(grep -E -v "(EH)|(C)$" test.txt | sort)
6.3.0.00.220EH
6.3.0.00.221EH
6.3.0.00.220C
6.3.0.00.221C
6.3.0.00.220
6.3.0.00.221

4 Comments

Look, I have updated my answer to show that is works.
I guess I am doing something wrong not working for me can we do it through sort command,
I have found an error. I forgot to sort each grep command's output. However, it migth be useful if you mention what doesn't work.
It removes the EH numbers and gives me the leftovers in the file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.