[Bash] grep command
The grep command searches for patterns within files and prints matching lines.
grep [options] [content] [file]
Search for a pattern in a file:
grep "pattern" filename.txt
Ignore case sensitivity:
grep -i "pattern" filename.txt
Search recursively in directories:
grep -r "partten" /path/to/directory
Show line numbers of matches:
grep -n "pattern" filename.txt
Example
vi exampletxt
Hello World
This is a sample file
Bash scripting is powerful
Learning grep, awk, and sed
Another line with the word World
Search file:
grep "World" example.txt
Hello World
Another line with the word World
grep -i "world" example.txt
Hello World
Another line with the word World
grep -n "line" example.txt
5:Another line with the word World
Search directory:
mkdir test_directory
echo "This is a sample text file" > test_directory/file1.txt
echo "Another sample text file" > test_directory/file2.txt
grep -ri "sample" test_directory # case insensitive
test_directory/file2.txt:Another sample text file
test_directory/file1.txt:This is a sample text file
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2023-05-17 [Rust] Enum
2021-05-17 [Cloud DA] Serverless Framework with AWS
2021-05-17 [AWS] Using APIGateway to validate API request
2020-05-17 [React Recoil] Write a Custom Recoil Hook to Reset a Value in the Recoil State
2019-05-17 [Functional Programming] propSatisfies with implies
2019-05-17 [Git] How to revert one file changes from one commit
2019-05-17 [Svelte 3] Use reactive declarations to compute component state in Svelte 3