Description
- A line may contain one or more lists enclosed by a pair of parentheses.
- Each list consists one or more members separated by commas.
- For simplicity, we assume there are no blanks inside a list.
- We want to remove members NOT beginning with `XX_' from every list.
|
| Raw Input
| item1 (XX_item2,item3,XX_item4) item5 (item6,XX_item7) item8
|
|
| Desired Output
| item1 (XX_item2,XX_item4) item5 (,XX_item7) item8
|
|
Script and Comments
Script1 [ 1] s/^[^()]*\(/&\n/
[ 2] :loop
[ 3] s/(\n[^()]*)\)/\1\n/
[ 4] h
[ 5] s/^.*\n(.*)\n.*/\1/
[ 6] s/(^|,)(XX_)/\1\n\2/g
[ 7] s/(^|,)[^\n][^ ,]*//g
[ 8] s/\n//g
[ 9] G
[10] s/^(.*)\n(.*)\n.*\n(.*)/\2\1)\n\3/
[11] s/\n([^()]*\()/\1\n/
[12] /\(\n/b loop
[13] s/\n//g
| |
|