스트림에서 특정 텍스트 라인 만 표시 및 파이프
문제
다음은 WordNet을 사용하여 사전 조회를위한 명령 줄 스크립트입니다.
#!/bin/bash
# Command line look up using Wordnet - command line dictionary
echo "Type in your word:"
read word
/usr/bin/curl -s -A 'Mozilla/4.0' 'http://wordnetweb.princeton.edu/perl/webwn?s='$word'&sub=Search+WordNet&o2=&o0=1&o7=&o5=&o1=1&o6=&o4=&o3=&h=' \
| html2text -ascii -nobs -style compact -width 500 | grep "*"
여기에 "hello"를 입력합니다. 출력은 다음과 같습니다.
Type in your word:
hello
**** Noun ****
* S:(n)hello, hullo, hi, howdy, how-do-you-do (an expression of greeting) "every morning they exchanged polite hellos"
나는 s : 이후의 문자열 만 원한다. 다음을 제거하고 싶습니다.
**** Noun ****
* S:
자체적으로 배관을 위해 이것을 남겨 둡니다 ->
(n)hello, hullo, hi, howdy, how-do-you-do (an expression of greeting) "every morning they exchanged polite hellos"
해결책 3
DigitalRoss의 답변을 추가하는 코드 작업이 있습니다.
#!/bin/bash
# Command line look up using Wordnet - command line dictionary
echo "Type in your word:"
read word
/usr/bin/curl -s -A 'Mozilla/4.0' 'http://wordnetweb.princeton.edu/perl/webwn?s='$word'&sub=Search+WordNet&o2=&o0=1&o7=&o5=&o1=1&o6=&o4=&o3=&h=' \
| html2text -ascii -nobs -style compact -width 500 | grep "*" | sed 's/^[^S]*S://' | grep -v "\*\*\*\* "
내가 믿는 모든 형식을 제거합니다. 그것은 제거합니다 **** Noun ****
라인도.
다른 팁
나는 당신이 그것을 바꾸면 그것을 믿습니다 sed -e
할 것 s/^.*S:/ /
또는 아마도 조심스럽게 조심스럽게 s/^[^S]*S://
당신은 당신이 원하는 것을 얻을 것입니다. SED 명령이 탭을 대체하는 경우 (말할 수 없음) 보존하고 싶을 수도 있습니다.
나는 무엇을 모른다 grep "*"
해야하지만 다음으로 변경할 수 있습니다.
grep -Eo '\(.*'
제휴하지 않습니다 StackOverflow