Created
October 9, 2013 11:02
-
-
Save dshipp/6899532 to your computer and use it in GitHub Desktop.
Use sed to match a regular expression and replace the full line with just the match.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Use \( and \) to create a match group in the find part, use \1 in the replace part to reference the match group. | |
echo "./ThingToMatch/other/stuff/" | sed -n 's/\.\/\([a-zA-Z0-9]*\)\/.*/\1/p' | |
# This will output: ThingToMatch | |
# Works with multiline input, applying the replacement to each line. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment