2013-06-20 4 views
1

.txt 디렉토리에 검색 및 추출 프로그램의 출력으로 생성 된 파일이 있습니다. .txt 파일의 형식은 다음과 같습니다.태그 내의 키워드를 기반으로 한 줄 삭제

키워드 Entrust에 기반하여 후 처리 단계로 sed을 사용하여 아래 라인을 삭제하려고합니다.

<content>This document has been digitally signed with external signatures using Entrust PKI</content> 

내가 쉘 스크립트에서 실행하고있어 sed 명령은 다음과 같습니다 : 더 라인 .txt 파일에서 제거하는 눈치. sed 태그 내의 콘텐츠를 기반으로 검색 및 삭제를 수행 할 수 있습니까? 내가 할 수있는 다른 방법이 있습니까?

sed '/Entrust/d' $file > ${file}.mod; 
<block> 
    <title> 
This is the title 
    </title> 
    </block> 
    <block> 
    <content> 
Content1 
    </content> 
    </block> 
    <block> 
    <title> 
Title 2 
    </title> 
    <content> 
some content 2 
    </content> 
    </block> 
    <block> 
    <title> 
Title 3 
    </title> 
    <content> 
some content 3 
    </content> 
    <content> 
This document has been digitally signed with external signatures using Entrust PKI 

    </content> 
    <content> 
some content4 

    </content> 
    <content> 
This document has been digitally signed with external signatures using Entrust PKI 
    </content> 
</block> 
+5

텍스트 파일을 말한다 Entrust, sed cmd가 위탁을 요청합니다 – John3136

+0

@simak Windows에서 텍스트 파일이 작성 되었습니까? 'Entrust'를 포함하는 줄을 지우고 싶습니까, 아니면 줄을 묶는 태그도 제거하고 싶습니까? –

+0

Entrust가 포함 된 행을 삭제하려고합니다. 감사! – BRZ

답변

1

지금까지 내가 당신이 txt 파일에서 삭제하려는 이해. 나는 그것에 대해 sed -i을 제안 할 것이다. 당신이 필요 라인이 명령

sed -i '/Entrust/d' $file 
0
sed -i 's/<content>This document has been digitally signed with external signatures using Entrust PKI</content>/#<content>This document has been digitally signed with external signatures using Entrust PKI</content>/g' $filename 

${file}.mod 삭제를 참조한다 이것은 당신이 스크립트에서 읽기/발견되지 않습니다 라인을 언급 할 수있는 방법입니다.

0
perl -lne 'print unless(/\bEntrust\b/)' your_file.txt > your_file.mod 
0

XML 스타일 태그 외부에서 텍스트를 검색하려면 아래 명령을 사용하십시오.

sed '/^\([^<]*\(<[^<>]*>\)*\)*Entrust/d' 

다음은 예입니다.

$ cat tmp.txt 
some content 2. 
some content with Entrust. 
<tag type='Entrust'/> 
<tag>Entrust</tag> 
$ sed '/^\([^<]*\(<[^<>]*>\)*\)*Entrust/d' tmp.txt 
some content 2. 
<tag type='Entrust'/> 

이 표현식은 줄 바꿈을 포함하는 태그를 처리하지 않습니다.

1

당신이 시도 할 수 :

sed -n '/Entrust/!p' $file > ${file}.mod 

또는

sed '/Entrust/d' $file > ${file}.mod 

awk '!/Entrust/' $file > ${file}.mod 
관련 문제