Skip to content

Instantly share code, notes, and snippets.

@ezirmusitua
Created January 17, 2019 15:48
Show Gist options
  • Save ezirmusitua/39bac15921f06302f20de174fa953077 to your computer and use it in GitHub Desktop.
Save ezirmusitua/39bac15921f06302f20de174fa953077 to your computer and use it in GitHub Desktop.
[Extract substring] extract substring with cut in bash #bash #linux
# 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