Skip to content

Instantly share code, notes, and snippets.

@nathanpc
Created June 18, 2011 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathanpc/1033208 to your computer and use it in GitHub Desktop.
Save nathanpc/1033208 to your computer and use it in GitHub Desktop.
Using Files As Databases
#!/bin/sh
# Access AddressBook file and use it as a database
# Variables
name=$1
number=$2
db=AddressBook
### AddressBook File Example ###
# Maria Daher (27)5564-4392 #
# Nathan Campos (27)3325-9732 #
# Thiago B. (32)5302-4892 #
# Lucas Pinher (23)0982-2389 #
# Eduardo V. (75)9234-8234 #
################################
# Listing what's on the file
cat $db
# Searching inside the file for the term inputted as the first argument
grep "$name" $db
# Adding someone on the file
echo "$name $number" >> $db # Add a new input on the file
sort -o $db $db # Organize the db/file content
# Deleting records from the file
grep -v "$name" $db > /tmp/$$ # Create the new file without the choosen record on /tmp/(PID)
mv /tmp/$$ $db # Overwrite the file with the one without the record removed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment