--- title: "sort numerically" seo_description: "how to sort lines numerically in unix shell" date: 2023-05-11T09:14:37+02:00 draft: false snippet_types: - sort --- Working with with sitemap xml files in AWS S3 today and the default sort is a bit hard to read. Example: ```shell $ aws s3 ls s3://cool-bucket | awk '{print $4}' sitemap.brands.xml sitemap.episode.0.xml sitemap.episode.1.xml sitemap.episode.10.xml sitemap.episode.11.xml sitemap.episode.2.xml sitemap.episode.20.xml sitemap.episode.21.xml sitemap.episode.22.xml sitemap.episode.23.xml ... ``` Using `sort -V` it sorts the lines numerically! Working example: ```shell $ aws s3 ls s3://cool-bucket | awk '{print $4}' | sort -V sitemap.brands.xml sitemap.xml sitemap.episode.0.xml sitemap.episode.1.xml sitemap.episode.2.xml sitemap.episode.3.xml sitemap.episode.4.xml sitemap.episode.5.xml sitemap.episode.6.xml sitemap.episode.7.xml ... ```