문제

I've got a YAML file with nodes such as:

group:
  name: test
  permissions:
  - i.can.(create|delete)

I need to replace i.can.(create|delete) with i.can.create and i.can.delete (there are many instances).

How can I do this easily?

도움이 되었습니까?

해결책 2

The idea is to replace all something(a|b|c|...) with lines somethinga somethingb etc.

awk seems to be suited here more than sed:

awk 'BEGIN { FS="[(|)]" ; OFS=""} /\(.*\)/ { for (field=2;field<NF;field++) {print $1,$field ;} ; next ; }1'

This will do what you wanted

다른 팁

This might work for you (GNU sed):

sed -r 's/^(.*\bi\.can\.)\((create)\|(delete)\)/\1\2\n\1\3/' file
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top