All pastes #534615 Raw Edit

simeon

public shellscript v1 · immutable
·published 2007-06-03 20:36 UTC
rendered paste body
#The $FILE has the following lines...#Apartment: "we party" with code :: 15#Apartment: "yeah" with code :: 66#Apartment: "i trance you" with code :: 666#Apartment: "heyiaaaaa" with code :: 1 # so when awk grabs $2 it can only take correctly that names with NO spaces!#          echo "**********************"     echo "Adding a new apartment..."     echo "**********************"     echo -n "Give me the name of the apartment house: "     read name     while true; do echo -n "Give me the code of that house: "     read code       if [ -f $FILE ]; then # Check if has some data and the same code...        IFS='"'        	awk -v cod=$code '$NF==cod { print $2 " " $NF}' $FILE > temp     	if [ -s temp ]; then        exists=`awk '{ $NF=" "; print $0 }' temp`             	echo "There is already a house named $exists with that code."     	rm \-rf temp     	continue     	else      	echo -n "Apartment: \"$name\" with code :: $code " >> $FILE     	echo >> $FILE     	echo "Apartment name: $name with code $code added successfully."      	break         fi