从模式匹配在bash文件结尾 [英] Match from pattern to end of file in bash
问题描述
我一直在试图找出如何使用的grep
在bash脚本从该文件末尾的模式相匹配。该文件并不总是相同数量的每一次行,而不是总是 [A-ZA-Z0-9]
。我试图从基于平面文件目录到一个数据库迁移。
I have been trying to figure out how to use grep
in a bash script to match from a pattern to the end of the file. The file is not always the same number of lines each time and is not always [A-Za-z0-9]
. I'm trying to migrate from a flat-file based catalog to a database.
文件摘录:
第一,最后:DOE,约翰·
ID:XXXXXXXX
...
First, Last: Doe, John ID: xxxxxxxx ...
案例说明:
这人不存在!
请不要加他了。
感谢。
我要抓住一切从'案例说明:到文件末尾。我似乎无法找到任何事情来帮助那里,因为没有一个实际的EOF字符。
I need to grab everything from 'Case Notes:' to the end of file. I can't seem to find anything to help out there as there isn't an actual EOF character.
想法?
推荐答案
这是 AWK
脚本可能会更加容易:
An awk
script might be easier:
awk '/^Case Notes:$/ { matched = 1 } matched { print }'
或者,如果你不希望看到的案例说明:
字符串本身,扭转它:
awk 'matched { print } /^Case Notes:$/ { matched = 1 }'
这篇关于从模式匹配在bash文件结尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!