문제

WordNet의 온라인 데이터베이스에서 읽은 Bash 스크립트를 구현하려고 노력했으며 하나의 명령으로 다양한 텍스트 파일을 제거 할 수있는 방법이 있는지 궁금합니다.

예제 filedump :

**** Noun ****
(n)hello, hullo, hi, howdy, how-do-you-do (an expression of greeting) "every morning they exchanged polite hellos"
**** Verb ****
(v)run (move fast by using one's feet, with one foot off the ground at any given time) "Don't run--you'll be out of breath"; "The children ran to the store"
**** Adjective ****
(adj)running ((of fluids) moving or issuing in a stream) "as mountain stream with freely running water"; "hovels without running water"

문법의 측면을 설명하는 선을 제거하면됩니다.

**** Noun ****
**** Verb ****
**** Adjective ****

단어의 정의 만있는 깨끗한 파일이 있습니다.

(n)hello, hullo, hi, howdy, how-do-you-do (an expression of greeting) "every morning they exchanged polite hellos"
(v)run (move fast by using one's feet, with one foot off the ground at any given time) "Don't run--you'll be out of breath"; "The children ran to the store"
(adj)running ((of fluids) moving or issuing in a stream) "as mountain stream with freely running water"; "hovels without running water"

문법 용어 주변의 * 기호는 SED에서 나를 넘어갑니다.

도움이 되었습니까?

해결책

해당 라인의 내용을 기반으로 파일에서 전체 줄을 선택하려면 grep 아마도 가장 적합한 도구 일 것입니다. 그러나 별과 같은 일부 캐릭터는 특별한 의미가 있습니다. grep, 백 슬래시로 "탈출"해야합니다. 이것은 4 개의 별과 공간으로 시작하는 선만 인쇄합니다.

grep "^\*\*\*\* " textfile

그러나 당신은 라인을 유지하고 싶습니다 ~하지 않다 그것을 일치 시키므로 필요합니다 -v 옵션 grep 그 일을합니다 : 선을 인쇄합니다 ~하지 않다 패턴과 일치합니다.

grep -v "\*\*\*\* " textfile

그것은 당신이 원하는 것을 줄 것입니다.

다른 팁

sed '/^\*\{4\} .* \*\{4\}$/d'

또는 약간 느슨합니다

sed '/^*\{4\}/d'
 sed 's/^*.*//g' test | grep .
# awk '!/^\*\*+/' file
(n)hello, hullo, hi, howdy, how-do-you-do (an expression of greeting) "every morning they exchanged polite hellos"
(v)run (move fast by using one's feet, with one foot off the ground at any given time) "Don't run--you'll be out of breath"; "The children ran to the store"
(adj)running ((of fluids) moving or issuing in a stream) "as mountain stream with freely running water"; "hovels without running water"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top