2011-03-09 92 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