Skip to content

Instantly share code, notes, and snippets.

@xbalaji
Last active March 7, 2024 01:15
Show Gist options
  • Save xbalaji/8063898885c35007e9c4d2d6dceb3903 to your computer and use it in GitHub Desktop.
Save xbalaji/8063898885c35007e9c4d2d6dceb3903 to your computer and use it in GitHub Desktop.
oneliners-bash
# split a file (sp500.csv) with 101 lines each with numeric suffixes and additional extension suffixes
split --numeric-suffixes=1 -l 101 sp500.csv stock --additional-suffix=".csv"; ls stock*.csv
# the output is as below
stock01.csv stock02.csv stock03.csv stock04.csv stock05.csv
# gnome graphical font size
# fontsize 1.5 <-- to make it bigger
# fontsize <-- to reset to normal
# fontsize 0.7 <-- to make it smaller
fontsize ()
{
[[ -n ${1} ]] && echo "setting" && gsettings set org.gnome.desktop.interface text-scaling-factor ${1};
[[ -z ${1} ]] && echo "reset" && gsettings reset org.gnome.desktop.interface text-scaling-factor
}
# lorem-epsum generate 40 lines of text
# curl generates 40 lines in a single paragraph, use awk to split each line at period and print with the record number
curl -sk http://metaphorpsum.com/sentences/40 | gawk 'BEGIN {RS="."} { gsub(/^ /,"", $0); printf "%2d %s\n", NR, $0}'
# using random generator from bash, 20 lines control with head
tr -dc a-z1-4 </dev/urandom | tr 1-2 ' \n' | awk 'length==0 || length>50' | tr 3-4 ' ' | sed 's/^ *//' | cat -s | sed 's/ / /g' | head | fmt
base64 /dev/urandom | awk '{print(0==NR%10)?"":$1}' | sed 's/[^[:alpha:]]/ /g' | head -50
# more of it here ---> https://unix.stackexchange.com/questions/97160/is-there-something-like-a-lorem-ipsum-generator
# sending api key/secrets using text message
# echo the secret string, using open ssl to encrypt it and then convert to hex string so it is easy to transfer
echo "myapikey" | openssl aes-256-ecb -a -pass "pass:<pass>" -e 2>/dev/null | xxd -u | cut -c1-50
# reverse operation; assuming you have the output of the above command in a text file out.txt
cat out.txt | xxd -r | openssl aes-256-ecb -a -pass "pass:<pass>" -d
# oneliner shell script + jq see filterjson.py for more explanation
while IFS= read -r line; do jq -r --arg id "$line" 'to_entries | .[] | select(.key == $id)' contents.json; done < keyfilter.txt | jq -s '.|from_entries'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment