Guest User

Untitled

a guest
Apr 26th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. # Grab the word after matching word
  2.  
  3. grep -oP "(?<=$word )[^ ]+"
  4.  
  5. For example, we wish to extract only `enp3s0` from the following output
  6.  
  7. $ ip r show default
  8. default via 10.0.0.100 dev enp3s0 proto static metric 100
  9.  
  10. $ word=dev
  11. $ ip r show default | grep -oP "(?<=$word )[^ ]+"
  12. enp3s0
  13.  
  14. # Bashrc entry
  15.  
  16. grepWordAfter(){
  17. [[ -n $1 ]] && grep -Po "(?<=$1\s)\w+";
  18. }
Add Comment
Please, Sign In to add comment