在Solaris上,似乎我需要单引号"匹配行的开头"表达式:
> sh
$ echo offset 0.000000 2>&1 | grep ^offset | tail -1
offset: not found
$ Usage: grep [-c|-l|-q] [-bhinsvwx] pattern_list [file ...]
grep [-c|-l|-q] [-bhinsvwx] [-e pattern_list]... [-f pattern_file]... [file...]
grep -E [-c|-l|-q] [-bhinsvx] pattern_list [file ...]
grep -E [-c|-l|-q] [-bhinsvx] [-e pattern_list]... [-f pattern_file]... [file...]
grep -F [-c|-l|-q] [-bhinsvx] pattern_list [file ...]
grep -F [-c|-l|-q] [-bhinsvx] [-e pattern_list]... [-f pattern_file]... [file...]
Run Code Online (Sandbox Code Playgroud)
我可以通过单引用正则表达式来轻松解决这个问题:
> sh
$ echo offset 0.000000 2>&1 | grep '^offset'| tail -1
offset 0.000000 …Run Code Online (Sandbox Code Playgroud)