Created
January 17, 2019 15:48
-
-
Save ezirmusitua/39bac15921f06302f20de174fa953077 to your computer and use it in GitHub Desktop.
[Extract substring] extract substring with cut in bash #bash #linux
This file contains hidden or 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
# one line | |
## explaination | |
### 1. echo something and pipe to cut for processing | |
### 2. -d<char> means cut string by char | |
### 3. -f<num> means get the second set of cutted result | |
echo 'someletters_12345_moreleters.ext' | cut -d'_' -f 2 | |
# multi line | |
INPUT='someletters_12345_moreleters.ext' | |
SUBSTRING=$(echo $INPUT| cut -d'_' -f 2) | |
echo $SUBSTRING |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment