Match from pattern to end of file in bash

寵の児 提交于 2019-11-28 13:54:56
ajk

An awk script might be easier:

awk '/^Case Notes:$/ { matched = 1 } matched'

Or if you don't want to see the Case notes: string itself, reverse it:

awk 'matched; /^Case Notes:$/ { matched = 1 }'

idiomatic awk solution would be

awk '/^Case Notes:$/,0'

prints from pattern (inclusive) to end of file.

sed -n '/^Case notes:/,$p' file >newfile

Few years late but you could use

more +"Case notes:" file

Pure bash can do it

declare -i tf=0
while read -r line
do
   case "$line" in
     *"Case notes"* ) tf=1;
   esac
   [[ $tf -eq 1 ]] && echo "$line"
done < file
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!