Grep can be used for finding text within a file or output from previous command. You can use Regex with grep (or egrep), which I cover in this video.
Bash Regex Cheatsheet:
Background from Charlie Henson:
Beach And Nebula –
Like my channel? Please help support it:
Patreon:
Paypal:
Follow me on Social Media
Google+
Twitter:
Minds:
Nguồn: https://ftlinuxcourse.com
Xem thêm bài viết khác: https://ftlinuxcourse.com/lap-trinh-linux
Xem thêm Bài Viết:
- Trải nghiệm mới hay ho với hướng dẫn cài Mac Os trên vmware
- Bật mí cách cài đặt ssl miễn phí lên Let’s Encrypt
- Tuyệt chiêu tạo usb boot kali linux đơn giản dành cho bạn
- Hướng dẫn chi tiết từ A – Z các bước cài đặt Python trên Windows 10
- Bật mí quy trình cài đặt Kali Linux trên Vmware đúng chuẩn và chi tiết
You can also return the lines around the matching line.
grep -A3 pattern filename will include the 3 lines after the match.
grep -B4 " " to include 4 lines before the match.
grep -C2 " " to include 2 lines before and 2 lines after the match.
Knowing Grep turns you from a competent IT guy into a full on hacker. Just need a black hoodie.
very helpful n precise. Sounds UK or Australian accent.
instead of:
$ ps -a | grep [[:space:]][[:digit:]][[:space:]]
can't you just do:
$ ps -a | egrep ' [0-9] '
or does that not always work?
If in a script and it's not huge file (or otherwise, performance isn't an issue), I always opt for a pure-shell appraoch in my programs, both personal and published on GitHub. For example, here I'm getting the currently used RAM, using just the two processes (bash and free):
while read -a X; do
if [ "${X[0]}" == "Mem:" ]; then
printf "%-'dMn" "${X[2]}"
break
fi
done <<< "$(/usr/bin/free -m)"
Whereas most people would wind up using bash, free, grep, cut, and God knows what else; I consider this massively inefficient and messy. That said, it really does depend on the task, and obviously this is more advanced than a simple grep and cut, but thought I'd still show passers-by my approach.
Noice.
I have to just take a moment to say how much I am loving this series. I love learning new things about commands I already knew, and new CLI commands, that can help me in my daily tasks
Please do a tutorial about cmatrix, sl, ddate and xlogo.
<3
GNU grep v. BSD grep feels like a missing section of this video. People using a Mac will in some instances have a much different experience without first installing core utils through some 3rd party source. I remember finding that out when I tried `grep -i…` in OS X years ago.
Worth mentioning : -F to search for non regex strings (faster when handling huge files)
Why do you hide the window decorations you present on ? I noticed that in your recent videos. Still on KDE Neon ?
Using grep -rn is a real life saver for coders, especially within a large codebase. I've been using it for years.