How to perform a 'grep' search that excludes line starting with “//”and its preceding spaces? [closed]

ⅰ亾dé卋堺 提交于 2020-01-11 13:51:11

问题


How to perform a 'grep' search which doesn't display any lines that have the comment marks "//" in the front of the line, but also ignore whitespace in front of the "//" marks?

I attempted grep your_search_pattern' where_to_look | grep -v '^//, but it does not ignore lines that have spaces before "//".


回答1:


 grep 'your_search_pattern' where_to_look | grep -v '^//'



回答2:


You might check out the man page for grep.

Some things pertaining to your question:

  • the -v switch will invert your search

  • ^ matches the beginning of the line.

You should be able to piece the rest together.

(edit: or look above.)




回答3:


Using awk you don't need to use multiple piped commands:

 awk '/paatern/ && !/^\/\//' file


来源:https://stackoverflow.com/questions/19085802/how-to-perform-a-grep-search-that-excludes-line-starting-with-and-its-prec

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!