PC & IT SUPPORT MADE EASY FORUM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Linux Random Name Picker Bash Script Example

Go down

Linux Random Name Picker Bash Script Example Empty Linux Random Name Picker Bash Script Example

Post by jamied_uk 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!


Last edited by jamied_uk on 7th September 2018, 23:08; edited 1 time in total
jamied_uk
jamied_uk
Admin

Posts : 3053
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Linux Random Name Picker Bash Script Example Empty Re: Linux Random Name Picker Bash Script Example

Post by jamied_uk 18th June 2018, 16:54

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
jamied_uk
jamied_uk
Admin

Posts : 3053
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Back to top

- Similar topics

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