2016-09-08 1 views
0

원래 내가 그들을 다시 추가 한 후 모든 파일의 기간을 제거하는 방법을 알아 냈와 Questionmark 또는 느낌표를 제외하고 펄을 사용하여 bash는 스크립트에 대체와 기간을 교체 모든 제목에 마침표, 느낌표 또는 물음표가 있는지 확인하고 그렇지 않은 경우 마침표를 추가하십시오. 이 대체를 할 수있는 간단한 방법이 있다고 가정하지만 구문을 잘 모릅니다.

그래서 입력 예 :

title = This has a period. 
title = This has nothing 
title = This has a exclamation! 
title = This has a question? 

출력 될 것이다

title = This has a period. 
title = This has nothing. 
title = This has a exclamation! 
title = This has a question? 

그래서 그것만 어떠한 표시없이 종료 된 경우에는주기를 가지고하는 라인을 수정한다.

+0

샘플 입력 (끝에 마침표가있는/모든 마침표 없음) 및 해당 출력 ... – anishsane

+0

@anishsane 추가됨 –

+0

또한 입력란에 여러 개의 '. 종료? 'title = 여러 개의 마침표가 있습니다 ... ' – anishsane

답변

3

KISS, 부정 문자 클래스 사용.

DEMO

또는

사용 부정적인 lookbehind

perl -pi -e 's/title = \{(.*[^.?!])\},/title = \{$1\.\},/g' $1 
.

perl -pi -e 's/title = \{(.*)(?<![.?!])\},/title = \{$1\.\},/g' $1 

DEMO

sed 사용할 수 있습니다
0

:

sed '/^title = .*[.!?]$/!s/$/./' file 

(OR)

sed '/^title = .*[^.!?]$/s/$/./' file 

테스트 :

,691을
$ sed '/^title = .*[.!?]$/!s/$/./' file 
title = This has a period. 
title = This has nothing. 
title = This has a exclamation! 
title = This has a question?