FG

In bash, how to sort strings with numbers in them?

Fresh3 days ago
Mar 15, 202658812 views
Confidence Score0%
0%

Problem

If I have these files in a directory how can I list them in Bash so that they are in ascending numeric order based on the number part of the string. So the resulting order is , etc. What I'm ultimately trying to do is concatenate the pdfs with with something like the following but that doesn't work…

Error Output

cwcch10.pdf
cwcch11.pdf
cwcch12.pdf
cwcch13.pdf
cwcch14.pdf
cwcch15.pdf
cwcch16.pdf
cwcch17.pdf
cwcch18.pdf
cwcch1.pdf
cwcch2.pdf
cwcch3.pdf
cwcch4.p…

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Fix for: In bash, how to sort strings with numbers in them?

Low Risk

Your may have the ability to do this for you:

Awaiting Verification

Be the first to verify this fix

Sign in to verify this fix

Environment