첫 번째 줄에서 시작하는 첫 번째 ---
- 숨겨진 된 블록을 제거하려는 의미를 이해합니다. 이 경우,
sed '1 { /^---/ { :a N; /\n---/! ba; d} }' filename
이것은 :
1 { # in the first line
/^---/ { # if it starts with ---
:a # jump label for looping
N # fetch the next line, append to pattern space
/\n---/! ba; # if the result does not contain \n--- (that is, if the last
# fetched line does not begin with ---), go back to :a
d # then delete the whole thing.
}
}
# otherwise drop off the end here and do the default (print
# the line)
당신이
---abc
정도로 시작하는 라인을 처리하는 방법에 따라 약간 (아마도에서
$
를 추가 패턴을 변경해야 할 수도 있습니다 전체 줄이
---
인 경우에만 끝이 일치 함). 거기에 귀하의 정확한 요구 사항에 약간 명확하지 않습니다. 전면 물질과 단지 전면 물질을 제거하려면
입력 및 출력을 지정할 수 있습니까? 내 이해는'---'과'---'안의 줄을 제거하기를 원한다. 그렇다면'sed -i -n '/ --- /,/---/d'[file]' – qqibrow
qqibrow를 써라. 쓰여진대로'sed' 명령은 너무 욕심 거리며 묻힌 것 이상을 제거 할 것이다. . – user3439894