
<li>
많은 index.html 페이지에서 다음 html 태그를 제거해야 합니다 .
<li>
<a href="https://forward.global.ssl.fastly.net/contributoragreements/" onclick="_gaq.push(['_trackEvent', 'ClickTracking', 'TopNav_Contact_Editorial', window.location.href]);">Editorial</a>
</li>
많은 파일에서 이것을 재귀적으로 제거해야 합니다. 따라서 Linux의 sed에서 정규식을 사용하는 것이 최선의 선택이라고 생각합니다. 여러 가지 방법으로 시도했지만 해결책을 찾지 못했습니다. index.html 파일 안에 다른 태그가 있지만 <li>
어쨌든 편집해서는 안 됩니다. 위에서 언급한 태그만 제거해야 합니다.
미리 감사드립니다.
답변1
문서 조각이 올바른 형식의 XHTML 파일의 일부라고 가정하면 값이 정확히 다음을 사용하는 속성 이 있는 노드를 li
포함하는 모든 노드를 삭제할 수 있습니다 .a
href
https://forward.global.ssl.fastly.net/contributoragreements/
xmlstarlet
xmlstarlet ed --delete '//li[a/@href = "https://forward.global.ssl.fastly.net/contributoragreements/"]' file.xhtml
문서가 올바른 형식의 XHTML 문서가 아닌 경우 먼저 복구를 시도할 수 있습니다.
xmlstarlet fo --recover --html file.html |
xmlstarlet ed --delete '//li[a/@href = "https://forward.global.ssl.fastly.net/contributoragreements/"]'
index.html
에서 부패한 디렉토리 구조의 모든 파일에 대해 이를 실행하려면 다음과 같이 top-dir
호출하십시오 .xmlstarlet
find
find top-dir -type f -name index.html -exec sh -c '
tmpfile=$(mktemp)
for pathname do
cp "$pathname" "$tmpfile"
xmlstarlet fo --recover --html "$tmpfile" |
xmlstarlet ed --delete "//li[a/@href = \"https://forward.global.ssl.fastly.net/contributoragreements/\"]" >"$pathname.new"
done
rm -f "$tmpfile"' sh {} +
index.html.new
위의 명령은 발견 된 각 파일에 대해 호출되는 새 파일을 생성합니다 index.html
. .new
위 명령에서 제거된 상태 로 실행하기 전에 이러한 파일을 살펴보고 문제가 없는지 결정해야 합니다 .
당신은 분명히 이것을 실행해야합니다복사테스트하는 동안 백업된 데이터.