Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Bash sort strings from an specific char

I have several rows of strings, and I want to sort them alphabetically, from the character @ forward.

I give you an example, I have this:

alice@example.com
austin@microsoft.com
berto@example.com
charles@test.com
dorian@microsoft.com

and I expect this output

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

alice@example.com
berto@example.com
austin@microsoft.com
dorian@microsoft.com
charles@test.com

So that they are sorted by the string after the "@"

Regards!

>Solution :

You can use the sort command for this:

sort -t@ -k2 inputfile
  • -t sets the delimiter to the @ character
  • -k2 use the second column to sort
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading