2011-03-09 2 views
0

이것은 코스의 자료입니다. 내 연구의 코드는 항상 오두막UNIX 셸 명령 및 파이프의 초보자 문제

#! /bin/sh 

로 시작한다 그리고 나는 또한 아마

wc, tail, grep, head 

의 조합을 사용해야이 문제를 해결하기 위해 생각하지만 문제가 함께이 퍼팅을 데. 도움을 많이 주시면 감사하겠습니다.

Write a shell command that processes a file 
that is 200 lines long or more. It outputs the number of those lines within lines 100 through 
199 *inclusive* that contain the character string “hello”. 


Write a shell command that outputs the number of lines in the lines range 
100..199 that contain "hello, " but is NOT followed by "world". 
+0

라인 카운트 시작 0 또는 1로합니까? 첫 번째 작업에서 –

+0

을 말한 경우 관련 줄의 줄 번호 만 인쇄해야합니까? –

답변

0

1 일

head -n 199 $FILE | tail -n 100 | grep "hello" | wc -l 

2 일

head -n 199 $FILE | tail -n 100 | grep "hello, " | grep -v "hello, world" | wc -l