正则表达式:grep支持使用正则表达式进行更灵活的匹配。正则表达式是一种强大的模式匹配工具,可以根据规则来匹配文本。例如,增加以下内容到data.txt文件:
apple banana orange grapefruit pineapple
grep "^a" data.txt:使用正则表达式^a,匹配以 “a” 开头的行。结果将显示 “apple”。grep "e$" data.txt:使用正则表达式e$,匹配以 “e” 结尾的行。结果将显示 “apple” 和 “pineapple”。