Linux Random Name Picker Bash Script Example
Page 1 of 1
Linux Random Name Picker Bash Script Example
./run.sh
- Code:
#!/bin/bash
# (C) J~Net 2018
#
# jnet.forumotion.com/t1638-linux-random-name-picker-bash-script-example#2520
#
#Example:
#
# ./run.sh
# Check names are available
file="fnames.txt"
if [ -f "$file" ]
then
echo "$file Female Names Found."
else
echo "$file Female Names Not Found."
echo "Getting Name Files, Please wait....."
sudo chmod +x *.sh && bash get_names.sh
fi
clear
# Now to pick a random name
#
echo "Random Female Name: "
sort --random-sort fnames.txt | head -n 1
echo ""
echo "Random Male Name: "
sort --random-sort mnames.txt | head -n 1
echo ""
# stackoverflow.com/questions/1803628/raw-list-of-person-names
# cyberciti.biz/faq/unix-linux-test-existence-of-file-in-bash
# stackoverflow.com/questions/448005/whats-an-easy-way-to-read-random-line-from-a-file-in-unix-command-line
get_names.sh
- Code:
#!/bin/bash
# (C) J~Net 2018
#
# Example:
# get_names.sh
#
curl -s http://deron.meranda.us/data/census-dist-female-first.txt | awk '{print $1}' > fnames.txt
#
#
curl -s http://deron.meranda.us/data/census-dist-male-first.txt | awk '{print $1}' > mnames.txt
(yes you could put above file contents inside the run.sh file but left it separate so you can get different lists from different sources)!
The run file will execute the get names file if required!
Last edited by jamied_uk on 7th September 2018, 23:08; edited 1 time in total
Re: Linux Random Name Picker Bash Script Example
Random Alias Plus Sirname Picker
- Code:
#!/bin/bash
# (C) J~Net 2018
#
# jnet.forumotion.com/t1638-linux-random-name-picker-bash-script-example#2520
#
#Example:
#
# ./run.sh
#
# to strip out all except aphla chars
# sed 's/[0-9.%]//g' lnames.txt > newlnames.txt
#
# Remove blank lines in a text file!
# awk NF lnames.txt > newlnames.txt
#
# Check names are available
file="fnames.txt"
if [ -f "$file" ]
then
echo "$file Female Names Found."
else
echo "$file Female Names Not Found."
fi
clear
# Pick Sirname
lnamevar=`sort --random-sort lnames.txt | head -n 1`
#
# Now to pick a random name
#
echo "Random Female Name: "
sort --random-sort fnames.txt | head -n 1
echo ""
echo "Random Male Name: "
sort --random-sort mnames.txt | head -n 1
echo ""
echo "Random Sirname"
echo "$lnamevar"
echo ""
# stackoverflow.com/questions/1803628/raw-list-of-person-names
# cyberciti.biz/faq/unix-linux-test-existence-of-file-in-bash
# stackoverflow.com/questions/448005/whats-an-easy-way-to-read-random-line-from-a-file-in-unix-command-line
# theunixschool.com/2014/08/sed-examples-remove-delete-chars-from-line-file.html
# serverfault.com/questions/252921/how-to-remove-empty-blank-lines-in-a-file-in-unix
# stackoverflow.com/questions/4651437/how-to-set-a-variable-to-the-output-of-a-command-in-bash
Similar topics
» Linux Bash Shell Script To Pick A Random Number From And To Range
» Linux BASH Script Running Commands and Functions From Bash Script and saving to varables
» BASH Linux Talking IP Script
» Convert MP4 To MP3 Linux Bash Script
» Linux Bash Dog Age Calculator Script
» Linux BASH Script Running Commands and Functions From Bash Script and saving to varables
» BASH Linux Talking IP Script
» Convert MP4 To MP3 Linux Bash Script
» Linux Bash Dog Age Calculator Script
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum