
저는 다음 두 명령을 결합한 우아한 솔루션을 찾고 있습니다.
sed -i '/Y/! s/replace/with/' /path/to/file
sed -i '/X/ s/replace/with/' /path/to/file
나는 노력했다
sed -i '/X/ /Y/! s/replace/with/' /path/to/file
이것은 작동하지 않습니다. 우아한 해결책이 있습니까?
답변1
아마도 그럴까요 sed '/X/ {/Y/! s/replace/with/}'
?
$ sed '/X/ {/Y/! s/replace/with/}' << EOF
X replace X
X replace Y
Y replace X
Y replace Y
EOF
X with X
X replace Y
Y replace X
Y replace Y