Code Monkey home page Code Monkey logo

php-natsort's Introduction

natsort

Introduction

Natural sorting is something that can be really useful in *nix shell programming. If you've ever used ls -1v, you've used natural sorting.

Sometimes this type of sorting is needed when ls can't be used (e.g., when lines within a file need to be sorted in this special way). This script solves this problem by providing a more generic interface to the feature.

See the official PHP documentation on the natsort() function. You will find a description of why this tool is useful along with a discussion of its limitations.

Function

The syntax for the invocation of the natsort script is as follows:

natsort [-i] [-r] [--] [FILE, ...]

Each file argument is read into memory, and the collection of lines is sorted before being printed to the standard output. If no arguments are specified, the lines to be sorted are read from the standard input.

The allowed options are:

  • -i ignores case
  • -r reverses the sort order
  • -- signals the end of options, remaining arguments are files

I've found the -i option to be particularly useful.

Suggested Use

When a use case is encountered that requires this utility, it will be quite obvious. This script was written because I grew tired of repeatedly hacking together a solution when this type of sorting was needed.

Use it through your editor or on the command line. It's clean and surprisingly helpful for such a simple script.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.