![sed로 파이프하기 전에 텍스트를 이스케이프하세요.](https://linux55.com/image/135020/sed%EB%A1%9C%20%ED%8C%8C%EC%9D%B4%ED%94%84%ED%95%98%EA%B8%B0%20%EC%A0%84%EC%97%90%20%ED%85%8D%EC%8A%A4%ED%8A%B8%EB%A5%BC%20%EC%9D%B4%EC%8A%A4%EC%BC%80%EC%9D%B4%ED%94%84%ED%95%98%EC%84%B8%EC%9A%94..png)
대체하기 위해 sed에 텍스트를 전달하고 있는데, 텍스트에 마음에 들지 않는 문자가 포함된 것 같습니다.
텍스트의 출처는 다음 git log graph
과 유사합니다.
ID- desc author
ID- desc author
알겠습니다. unescaped newline inside substitute pattern
sed로 연결하기 전에 모든 것을 어떻게 피합니까?
Example:
COMMIT=$(git log my_branch...origin/master --pretty=format:'%h %an')
FINAL=$(cat msg.txt | sed -E "s/--PLACEHOLDER--/$COMMIT/)
답변1
간단한 bash 매개변수 대체를 통해 이를 수행할 수 있습니다.
msg=$(< msg.txt)
# or, for this demo
msg="This is the commit message.
--PLACEHOLDER--
That's it."
commit="id1 - message 1
id2 - message 2
id3 - message 3"
final="${msg//--PLACEHOLDER--/"$commit"}"
echo "$final"
This is the commit message.
id1 - message 1
id2 - message 2
id3 - message 3
That's it.