Loading...
More Shell Posts
#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 inputsed -z -r -e 's/\./\\\./g ; s/\-/\\\-/g' -e 's/\n/\)\|\(/g' -e 's/\|\($//' -e 'i/\(' -e 'a/!d' $1 | sed -r -f - $2
#!/bin/bash#Leif Messinger lsm0147#credit.sh FILEScred="Leif Messinger lsm0147"for bruh; doif [[ $bruh =~ \.cpp|\.c|\.java|\.js ]]; thencomment="//$cred"else#Basically everything else gets a pound sign comment#Pound signs are standard across linux. bash, sed, gawk, python etc#Speaking of which, I need to escape it because of that.comment="\#$cred"fiif [ -s $bruh ]; then#If the file has a shebangif egrep -q '^#!/' $bruh; thensed -i "/^\#!\//a$comment" $bruhelsesed -i "1i$comment" $bruhfielseecho "$comment" > $bruhfidone
echo -e ${PATH//:/\\n} | awk '{print length, $0}' | sort -n | cut -f2- -d' '
# Run "test" script on all packagesnpm run test --workspaces# Tip - this also works:npm run test -ws----------------------------------------------------# Runs "test" only on package-anpm run test --workspace package-a# Tip - this also works:npm run test -w package-a----------------------------------------------------# Install `lodash` on `package-a`npm install lodash --workspace package-a# Install `tap` on `package-b` as a dev dependencynpm install tap --workspace package-b --save-dev# Install `package-a` on `package-b`npm install package-a --workspace package-b# Install `eslint` in all packagesnpm install eslint --workspaces
awk '\{ for (i=1; i<=NF; i++) { ++D[$i]; } }\END { for (i in D) { print i, D[i] } }\' words.txt | sort -nr -k 2
# Three ways of checking if a file exists in a shell scriptFILE=/etc/resolv.confif test -f "$FILE"; thenecho "$FILE exists."fiif [ -f "$FILE" ]; thenecho "$FILE exists."fiif [[ -f "$FILE" ]]; thenecho "$FILE exists."fi