Skip to content

Instantly share code, notes, and snippets.

@rohan-molloy
Last active October 27, 2019 03:21
Show Gist options
  • Save rohan-molloy/2b861c6156bf0f560f614a696a75e939 to your computer and use it in GitHub Desktop.
Save rohan-molloy/2b861c6156bf0f560f614a696a75e939 to your computer and use it in GitHub Desktop.

Grep the word after match

example: "echo 'The quick brown fox' | wordafter quick" will return 'brown'

wordafter() {
  word="$1";
  grep -Po '(?<='$word')\W*\K[^ ]*';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment