2012-10-02 2 views
1

에서 추출 URL이 나는이 파일 (dev1.temp)가 있습니다. 출력은 다음과 같습니다가 완벽하게 작동배쉬 XML 파일

# Make a temp file with all the files url's  
grep -o 'url=['"'"'"][^"'"'"']*['"'"'"]' $temp_folder"/devel1.temp" > $temp_folder"/devel2.temp" 
# Strip off everything to leave just the url's'  
sed -e 's/^url=["'"'"']//' -e 's/["'"'"']$//' $temp_folder"/devel2.temp" > $temp_folder"/devel.temp" 

어제 :

include/sa/index.xml 
content/sa.xml 
include/global/index.xml 
include/orientation/index.xml 
include/movecamera/index.xml 
content/movecamera.xml 
include/fullscreen/index.xml 
include/instructions/index.xml 
include/coordfinder/index.xml 
include/editor_and_options/index.xml 

나는 다음과 같은 스크립트가 트릭을 수행하려면. 오늘 devel2.temp 및 devel.temp 출력은 다음과 같습니다.

[01;31m[Kurl="include/sa/index.xml"[m[K 
[01;31m[Kurl="content/sa.xml"[m[K 
[01;31m[Kurl="include/global/index.xml"[m[K 
[01;31m[Kurl="include/orientation/index.xml"[m[K 
[01;31m[Kurl="include/movecamera/index.xml"[m[K 
[01;31m[Kurl="content/movecamera.xml"[m[K 
[01;31m[Kurl="include/fullscreen/index.xml"[m[K 
[01;31m[Kurl="include/instructions/index.xml"[m[K 
[01;31m[Kurl="include/coordfinder/index.xml"[m[K 
[01;31m[Kurl="include/editor_and_options/index.xml"[m[K 

무슨 일이 벌어지고 있는지에 대한 아이디어가 있습니까?

답변

3

grep처럼 출력이 터미널이 아닌 경우에도 ANSI 시퀀스를 사용하여 출력을 표시합니다. --coloralways에서 auto으로 변경하십시오.

+0

자리에서 (즉,이 문제에 대한 과잉이다하지만 그것은, XPath는 2.0 지원하는 대부분의 반대로). 문제 해결됨! 감사!!! – RafaelGP

2

추가로 choroba 님의 댓글이 게시되었습니다. ANSI 시퀀스, 가능하면 sed 등을 통해 XML 구문 분석을 피하고 XML 인식 스크립팅 도구를 사용합니다. 나는 XMLStarlet toolkit을 사용합니다. 스크립트가 문자 인코딩/엔티티 인식 및 XML 변경에 직면 한 강력한 기능을 의미합니다.

2

xpath와 같은 xpath 도구를 사용해보십시오. 나는이 좋을 것 :

xpath -e "/krpano/include/@url" -q yourFile.xml | cut -f 2 -d "=" | sed 's/"// 

당신은 XML이 include 년대 만 url 속성을 갖는 krpano 루트있을 것이라는 점을 확신합니다. 밑줄을 긋기 위해 아래를 사용할 수도 있지만, 위의 명령은 더 빨리 실행됩니다.

xpath -e "//@url" -q yourFile.xml | cut -f 2 -d "=" | sed 's/"// 
1

세 번째 XML 관련 스크립트 도구는 내 Xidel입니다 :

xidel /tmp/your.xml -e //@url