2011-03-09 93 views
0

這是來自課程的材料。從我的研究代碼將始終與家當UNIX shell命令和管道中的初學者問題

#! /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線計數開始? – 2011-03-09 16:29:08

+0

在第一個任務中,你的意思是你只需要打印相關行的行號? – 2011-03-09 16:36:10

回答

0

一號任務

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

第二個任務

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