Linux Random Name Picker Bash Script Example

Go down

Linux Random Name Picker Bash Script Example

Post by jamied_uk on 14th June 2018, 12:38



./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!
avatar
jamied_uk
Admin

Posts : 2408
Join date : 2010-05-09
Age : 35
Location : UK

http://address-shortner.co.uk

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum