UNIX shell 命令和管道的初学者问题

发布于 10-20 23:06 字数 547 浏览 4 评论 0原文

这是课程中的材料。根据我的研究,代码总是以 shebang 开头

#! /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".

this is material from a course. From my research the code will always begin with the shebang

#! /bin/sh

And I also figured to solve this I would probably need to use a combinations of

wc, tail, grep, head

But I am having trouble putting this together. Help would be much appreciated.

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".

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难忘№最初的完美2024-10-27 23:06:03

第一个任务

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

1st task

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

2nd task

head -n 199 $FILE | tail -n 100 | grep "hello, " | grep -v "hello, world" | wc -l
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文