Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Grab the word after matching word
- grep -oP "(?<=$word )[^ ]+"
- For example, we wish to extract only `enp3s0` from the following output
- $ ip r show default
- default via 10.0.0.100 dev enp3s0 proto static metric 100
- $ word=dev
- $ ip r show default | grep -oP "(?<=$word )[^ ]+"
- enp3s0
- # Bashrc entry
- grepWordAfter(){
- [[ -n $1 ]] && grep -Po "(?<=$1\s)\w+";
- }
Add Comment
Please, Sign In to add comment