Skip to main content

Jan 12, 2023LeifMessinger

More Shell Posts

Search file with word list fast

Feb 22, 2022LeifMessinger

0 likes • 1 view

#Leif Messinger
#For when you want to search a lot of words in a file fast
#Arg 1 is the argument the list of words you want to search
#Arg 2 is the file you want to search
#-z means that it looks at the file as a whole, just treating newlines a characters.
#-r is regex. Needed for $, even tho the documentation says you don't need it. They are liars.
#First command replaces all . with \. and all - with \-
#Second command takes all newlines and replaces them with )|(
#Third command takes the trailing |( and deletes it
#Forth command puts a /( at the start
#Fith command puts /!d at the end. This tells it to not delete any lines that match the pattern.
#The second sed takes the output of the first sed as a command that searches any of the combined words
#-f - takes a command from the input
sed -z -r -e 's/\./\\\./g ; s/\-/\\\-/g' -e 's/\n/\)\|\(/g' -e 's/\|\($//' -e 'i/\(' -e 'a/!d' $1 | sed -r -f - $2

LeetCode #192: Word Frequency

Oct 15, 2022CodeCatch

0 likes • 58 views

awk '\
{ for (i=1; i<=NF; i++) { ++D[$i]; } }\
END { for (i in D) { print i, D[i] } }\
' words.txt | sort -nr -k 2

Find data-testids

Jul 8, 2024CHS

0 likes • 12 views

# Set the directory to search
# Set the output file
# Clear the output file
# Find all .tsx files in the specified directory and its subdirectories
find "$DIRECTORY" -type f -name "*.tsx" | while read -r FILE
# Search for instances of 'data-testid="testid"' and append them to the output file
grep -o 'data-testid="[^"]*"' "$FILE" >> "$OUTPUT_FILE"
# Search for instances of "'data-testid': 'testid'" and append them to the output file
grep -o "'data-testid': '[^']*'" "$FILE" >> "$OUTPUT_FILE"
echo "Search complete. Test IDs written to $OUTPUT_FILE."

Sep 30, 2021LeifMessinger

0 likes • 0 views

touch /tmp/login1.txt /tmp/login2.txt
while [ true ]
who | gawk '{ print $1 }' > /tmp/login2.txt
comm -13 /tmp/login1.txt /tmp/login2.txt
#Just a bit easier to read
#diff /tmp/login1.txt /tmp/login2.txt
cat /tmp/login2.txt > /tmp/login1.txt
sleep 1

Mar 21, 2021LeifMessinger

0 likes • 0 views by Leif Messinger
#./ [ADDRESS] to search
#./ [ADDRESS] & to search in the background
ping_cancelled=false # Keep track of whether the loop was cancelled, or succeeded
until ping -c1 "$1" >/dev/null 2>&1; do :; done & # The "&" backgrounds it
trap "kill $!; ping_cancelled=true" SIGINT
wait $! # Wait for the loop to exit, one way or another
trap - SIGINT # Remove the trap, now we're done with it
if [ "$ping_cancelled" == true ] #
printf "The pinger for $1 just closed bro.\n"
printf "$1 IS UP BROOO\a\n"


Nov 23, 2021LeifMessinger

0 likes • 1 view

#Makes a directory ./monkeys and puts every single bored bored ape yacht club monkey in there
#Leif Messinger
let OFFSET=0
let LIMIT=100
mkdir monkeys
function parseResults(){
sed 'y/,/\n/' | sed -e '/storage.opensea/d' -e '/https:\/\/\/Ju9CkWtV-1Okvf45wo8UctR-M9He2PjILP0oOvxE89AyiPPGtrR3gysu1Zgy0hjd2xKIgjJJtWIc0ybj4Vd7wv8t3pxDGHoJBzDB=s120/d' | egrep '"image_url":"(.*)"' | tr -d '\"' | sed 's/image_url://'
function downloadMonkeys(){
while read -r line; do
name=`echo "$line" | sed 's/https:\/\/\///'`
wget -q -O "./monkeys/$name.png" "$line" &
function queryMonkeys(){
let progress=($OFFSET*100)/$LIMIT
echo "Progress: $progress%"
result=`curl -s --request GET --url "$OFFSET&limit=$BATCHSIZE&collection=boredapeyachtclub"`
if [[ "$result" =~ "Request was throttled" ]] || [ "$result" == "" ]; then
#Retry download
sleep 10
#Download Monkeys
echo "$result" | parseResults | downloadMonkeys
#If not out of bounds, recurse
if [ "$OFFSET" -lt "$LIMIT" ] || [[ "$result" =~ '"assets":[]' ]]; then
echo "Downloading your monkeys into ./monkeys asynchronously."