수색…


소개

sed 의 분기 작업은 프로그램의 흐름을 제어하는 ​​데 도움이 될 수 있습니다.

무조건 분기로 대체하는 여러 줄 정규식 수행

in.txt 라는 파일이 있다고 가정합니다.

$ cat in.txt
a
b
a
c
a
d

나는 a\ncdeleted 것으로 만 바꾸고 싶지만 a\nb 또는 a\nd 바꾸고 싶지는 않다.

$ sed -e ':loop         # create a branch/label named `loop`
 $!{
 N                      # append the next line of input into the pattern space
 /\n$/!b loop           # If it is not the last line go to the `loop` branch again
 }
 s/a\nc/"deleted"/' in.txt    # do replacing in the pattern space

a
b
"deleted"    # see! succeed
a
d


Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow