[英]How can I print out all lines of a file containing a specific String in unix
I know how to print out the line of the first occurrence of the String but I'm not sure how to print out all occurrences. 我知道如何打印出第一次出现的String的行,但我不知道如何打印出所有出现的内容。 To print out the first occurrence of my String I have used
打印出我用过的第一次出现的String
grep ",1," my_course.
I feel like printing out all occurrences would look something like: 我觉得打印出来的所有事件看起来都像是:
while(file has next line)
grep ",1," my_course
I'm not sure how to do this while loop though. 我不知道如何在循环时这样做。 How do I test if file has next line.
如何测试文件是否有下一行。
EDIT: Sorry guys I thought grep only matched the first occurrence. 编辑:对不起家伙我认为grep只匹配第一次出现。 When I ran it, it only matched 1 line.
当我运行它时,它只匹配1行。 I didn't know only 1 line matched
我不知道只有1行匹配
Also, bonus question if someone wants to answer... if all the lines in my file (my_course) look like "number,name,credit hours,grade" how would I get all the grades in the file and store into an array? 此外,如果有人想要回答的话还有额外的问题...如果我的文件中的所有行(my_course)看起来像“数字,名称,学分,成绩”,我将如何获得文件中的所有成绩并存储到数组中?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.