Skip to main content
There's no need for '+' since you're only matching on and inserting before the left-most numeric character (it doesn't matter if there are more after or not). This also allows the solution to work with BSD sed (e.g. in OS X), which only supports basic regular expressions (which don't include '+').
Source Link

You can use a temporary sentinel character to delimit the number:

$ sed 's/\([0-9]\+\9]\)/;\1/' log | sort -n -t\; -k2,2 | tr -d ';'

Here, the sentinel character is ';' - it must not be part of any filename you want to sort - but you can exchange the ';' with any character you like. You have to change the sed, sort and tr part then accordingly.

The pipe works as follows: The sed command inserts the sentinel before any number, the sort command interprets the sentinel as field delimiter, sorts with the second field as numeric sort key and the tr commandscommand removes the sentinel again.

And log denotes the input file - you can also pipe your input into sed.

You can use a temporary sentinel character to delimit the number:

$ sed 's/\([0-9]\+\)/;\1/' log | sort -n -t\; -k2,2 | tr -d ';'

Here, the sentinel character is ';' - it must not be part of any filename you want to sort - but you can exchange the ';' with any character you like. You have to change the sed, sort and tr part then accordingly.

The pipe works as follows: The sed command inserts the sentinel before any number, the sort command interprets the sentinel as field delimiter, sorts with the second field as numeric sort key and the tr commands removes the sentinel again.

log denotes the input file - you can also pipe your input into sed.

You can use a temporary sentinel character to delimit the number:

$ sed 's/\([0-9]\)/;\1/' log | sort -n -t\; -k2,2 | tr -d ';'

Here, the sentinel character is ';' - it must not be part of any filename you want to sort - but you can exchange the ';' with any character you like. You have to change the sed, sort and tr part then accordingly.

The pipe works as follows: The sed command inserts the sentinel before any number, the sort command interprets the sentinel as field delimiter, sorts with the second field as numeric sort key and the tr command removes the sentinel again.

And log denotes the input file - you can also pipe your input into sed.

explained pipe
Source Link
maxschlepzig
  • 59.7k
  • 53
  • 224
  • 298

You can use a temporary sentinel character to delimit the number:

$ sed 's/\([0-9]\+\)/;\1/' log | sort -n -t\; -k2,2 | tr -d ';'

Here, the sentinel character is ';' - it must not be part of any filename you want to sort - but you can exchange the ';' with any character you like. You have to change the sed, sort and tr part then accordingly.

The pipe works as follows: The sed command inserts the sentinel before any number, the sort command interprets the sentinel as field delimiter, sorts with the second field as numeric sort key and the tr commands removes the sentinel again.

log denotes the input file - you can also pipe your input into sed.

You can use a temporary sentinel character to delimit the number:

$ sed 's/\([0-9]\+\)/;\1/' log | sort -n -t\; -k2,2 | tr -d ';'

You can use a temporary sentinel character to delimit the number:

$ sed 's/\([0-9]\+\)/;\1/' log | sort -n -t\; -k2,2 | tr -d ';'

Here, the sentinel character is ';' - it must not be part of any filename you want to sort - but you can exchange the ';' with any character you like. You have to change the sed, sort and tr part then accordingly.

The pipe works as follows: The sed command inserts the sentinel before any number, the sort command interprets the sentinel as field delimiter, sorts with the second field as numeric sort key and the tr commands removes the sentinel again.

log denotes the input file - you can also pipe your input into sed.

Source Link
maxschlepzig
  • 59.7k
  • 53
  • 224
  • 298

You can use a temporary sentinel character to delimit the number:

$ sed 's/\([0-9]\+\)/;\1/' log | sort -n -t\; -k2,2 | tr -d ';'