Register
It is currently Thu Jul 24, 2014 10:56 am

quick and dirty note keeping


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Tue Nov 21, 2006 2:39 pm   
Site Admin
User avatar

Joined: Sun May 15, 2005 9:36 pm
Posts: 662
Location: Des Moines, Iowa
I decided to create a very quick and dirty note keeping utility.... no gui, no menu interface.

Here is the code....

Code:
#! /bin/sh
# File: notes
# Description: Simple Note keeping script.
# Alias to "n"  # alias n='sh /home/crouse/scripts/notes.sh'
# USAGE EXAMPLES: 
#n a "This is a note"  (adds the line enclosed in quotes)
#n d 2 (removes line 2)
#n l (lists all lines)
#n s EXPRESSION (searchs for EXPRESSION)
# Options: a=add d=delete (or r=remove) l=listall s=search
# Set your paths below - next 2 lines
FILEPATH="/home/crouse"
FILE="notes.txt"

touch ${FILEPATH}/${FILE}

if [ "$1" = "a" ] ; then
  echo $2 >> ${FILEPATH}/${FILE}
fi

if [ "$1" = "s" ] ; then
  grep -i "$2" ${FILEPATH}/${FILE} | less
fi

if [ "$1" = "d" ] || [ "$1" = "r" ] ; then
  numberoflines=`less ${FILEPATH}/${FILE} | wc -l`
  bottompartoffile=`echo $((${numberoflines}-${2}))`
  headvar=`echo $((${2}-1))`
  head -n ${headvar} ${FILEPATH}/${FILE} > /tmp/notes
  tail -n ${bottompartoffile} ${FILEPATH}/${FILE} >> /tmp/notes
  mv /tmp/notes ${FILEPATH}/${FILE}
fi

if [ "$1" = "l" ] ; then
  nl ${FILEPATH}/${FILE} | less
fi

if [ "$1" = "clear" ] ; then
  rm -f ${FILEPATH}/${FILE} #removes ALL NOTES !!
fi

exit 0


To add someting to the file.....
Code:
[15:39:51 crouse]$ n a "This is a note"


To search the file
Code:
[15:42:49 crouse]$ n s "note"


To list ALL notes
Code:
[15:43:37 crouse]$ n l


To delete/remove a line..... (view all.... REMEMBER the LINE NUMBER ;) )
Code:
[15:43:37 crouse]$ n r 1


Simple but effective...


Top
 Profile WWW  
 PostPosted: Wed Nov 22, 2006 5:51 am   
User avatar

Joined: Mon Jul 03, 2006 8:58 pm
Posts: 52
Location: Rochester, NY
Neat. My dad uses a slightly more manual version of this (i.e. he opens a text editor and adds/removes info from the file). I like the idea.


Top
 Profile WWW  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP