There is an example in this link about sed:
To delete the first number on all lines that start with a "#" use:
sed '/^#/ s/[0-9][0-9]*//'
What is the benefit of first pattern(/^#/)? It could be simply:
sed 's/^#[0-9][0-9]*//'
|
There is an example in this link about To delete the first number on all lines that start with a "#" use:
What is the benefit of first pattern(
|
|||
|
The general format of
When a command has a single address, it operates on all lines that match that address. When a command has no address, it operates on every single line. Reference: POSIX Regarding your specific examples:
|
||||
|
|
|
The first will match and substitute:
The second will not. Plus, the second will also remove the initial |
|||
|
|
[0-9][0-9]*why not[0-9]\+? – Bernhard Apr 18 '12 at 6:39\+is guaranteed by POSIX. – jw013 Apr 18 '12 at 7:22\+is in POSIX extended regular expressions. en.wikipedia.org/wiki/Regular_expression#Syntax – Majid Azimi Apr 18 '12 at 7:54seduses BRE's though. – jw013 Apr 18 '12 at 8:50-r, other times with flag-E), and there is talk of adding this capacity to the POSIX standard forsed. @jw013 is correct though that the current POSIX standard doesn't requiresedto handle anything other than BREs. EREs handle plain+; somesedimplementations enhance their BREs to also handle\+, but if I remember rightly, this is not part of POSIX. Instead ofp\+you could usep\{1,\}, which is a POSIX BRE. – dubiousjim Oct 16 '12 at 15:51