Skip to content

Instantly share code, notes, and snippets.

View kbbgl's full-sized avatar

Ko Ga kbbgl

View GitHub Profile
@kbbgl
kbbgl / a.sh
Created May 7, 2020 16:56
[match x or inifinte times] #regex
# use {x,} to match string with x+ characters
echo "hello world reallylongword" | grep -P "\w{6,}" -o # will match reallylongword
@kbbgl
kbbgl / m.sh
Created May 7, 2020 16:57
[match x amount of times using iterations] #regex
# using the {x} will match whatever comes before it x amount of times
echo "12341234444412354444" | grep -P "4{3}" # will match 3 times '444'
# using the {x,y} will match a range from x to y
echo "12341234444344412354444" | grep -P "4{1,4}" # will match 4, 4444, 444, 4444[
@kbbgl
kbbgl / q.sh
Created May 7, 2020 16:57
[match non-greedy] #regex
# using the ? means that we're not matching greedily
echo "<p>Paragraph 1</p><p>Paragraph 2</p><p>Paragraph 3</p>" | grep -P "<p>.*?</p>" # will match <p>Paragraph 1</p>, <p>Paragraph 2</p>, <p>Paragraph 3</p>
# we can use the ? to match an optional character
echo "http:\\website.com,https:\\website2.com" | grep -P "https?.*"
@kbbgl
kbbgl / a.sh
Created May 7, 2020 16:58
[match chunks 0+ times] #regex
# match 0 or more times using * quantifier
echo "hello, how are you?" | grep -e "[a-z]*" # will match hello, how, are, you
# match all numbers in chunks with length of one or more with + quantifier
echo "47427 8381481 5813471" | grep -P "[0-9]+"
echo "47427 8381481 5813471" | grep -P "\d+"
@kbbgl
kbbgl / a.sh
Created May 7, 2020 16:59
[match character classes] #regex
# Vowels
echo abcdefghijk | grep -e "[aeiou]"
# will find a,e,i
# Range
echo abcdefghijkAC04 | grep -e "[a-zA-D0-9]"
# Negation character ^ - don't match
@kbbgl
kbbgl / regex.sh
Created May 7, 2020 16:59
[pattern to match string between <>] #regex
(?<=<).*?(?=>)
@kbbgl
kbbgl / a.sh
Created May 7, 2020 17:01
[output regex matches in new line] #bash #grep #regex
echo "12341234444344412354444" | grep -P "4{2,4}?" -o
44
44
44
44
44
@kbbgl
kbbgl / a.sh
Last active May 7, 2020 17:06
[Linux | run remote commands] #linux #bash #ssh
ssh -i /path/to/pem.pem user@IP 'df -h'
@kbbgl
kbbgl / proc_bg.sh
Created May 7, 2020 17:02
[run script in background] #linux #bash
# give executable permissions to script
chmod u+x run_monitoring
# run script in background and get pid for killing to stdout
nohup ./run_monitoring.sh > monitor_metrics.txt 2>&1 &
# save PID to kill
echo $! > save_pid.txt
# to kill process
@kbbgl
kbbgl / dict.md
Last active May 20, 2020 13:28
[ec logs dictionary] List of useful texts to look in ec logs #sisense #logs #ec #build

Custom table start

"starting to write N custom columns for table"

Custom table end

"finished writing 1 custom column for table"

Start build

"StartBuild"

Starting of copy