Monday, February 29, 2016

sed: Using Positional Groupings with \( \) and \1,\2

Use \( \) to save part of a regular expression and \1 and  \2 to recall them.

bash-4.2# cat test_h
1..........5
5.........10
10........20
100......200

bash-4.2# sed -e 's/\([0-9][0-9]*\)\.\{5,\}\.\([0-9][0-9]*\)/\1-\2/' test_h


1-5
5-10
10-20
100-200

No comments:

Post a Comment