Created
June 18, 2011 15:53
-
-
Save nathanpc/1033208 to your computer and use it in GitHub Desktop.
Using Files As Databases
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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