How to make grep stop at first match on a line?

前端 未结 4 1333
Happy的楠姐
Happy的楠姐 2021-02-14 08:03

Well, I have a file test.txt

#test.txt
odsdsdoddf112 test1_for_grep
dad23392eeedJ test2 for grep
Hello World test
garbage

I want to extract strings which h

4条回答
  •  無奈伤痛
    2021-02-14 08:32

    If we want to extract all meaningful input before garbage and actually stop on first match then -B NUM, --before-context=NUM option may be useful to "print NUM lines of leading context before matching lines".

    Example:

    grep --before-context=999999 "Hello World test"
    

提交回复
热议问题