Pages

Monday, February 18, 2019

SED Options

Example HTML page
We know sed command is used for file processing.

To Match Digit

sed -r 's/([^0-9]*([0-9]*)){2}.*/\2/' file

This extracts the second number:


sed -r 's/([^0-9]*([0-9]*)){1}.*/\2/' file

sed 's/[[:digit:]]\+\.//g'

$ echo "This is an example: 65 apples" | sed -r  's/^[^0-9]*([0-9]+).*/\1/'

65

59

Two problems:

sed does not support \d. Use [0-9] or [[:digit:]].


+ must be backslashed to get the special meaning: \+.

sed -r 's/.*_([0-9]*)\..*/\1/g'

No comments:

Post a Comment