Created
November 4, 2009 16:02
-
-
Save rkumar/226151 to your computer and use it in GitHub Desktop.
shell script to add data to top of given file in consistent format
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/bash | |
#*******************************************************# | |
# Usage: pass in a file name | |
# Log things into a file in one consistent format # | |
# I needed to change IFS else newlines were getting hogged# | |
# 2009-10-10 09:46 changed rlwrap to use a tmp file | |
#and vim to edit. | |
#Also using an ex command to add text to top of file. | |
# Arunachalesha # | |
# $Id$ # | |
#*******************************************************# | |
#TMPFILE=/usr/tmp/junk.$$ | |
#trap 'rm -f $TMPFILE; exit 0' 1 2 15 | |
if [ $# -eq 0 ] | |
then | |
echo "I got no filename" | |
exit 1 | |
fi | |
today=$(date +"**Date: %Y-%m-%d %H:%M**") | |
logfile=$1 | |
OLDIFS=$IFS | |
#IFS="~" | |
echo Try to stick to maruku or markdown format | |
echo End with Ctrl-D, Ctrl-C to abort | |
echo " " | |
echo -n "Enter title: " | |
read title | |
#text=`rlwrap cat` | |
tmpfile=`mktemp -t DIARY` | |
#cat >> $logfile | |
#mv $logfile $logfile.tmp | |
echo $today >> $tmpfile | |
echo "" >> $tmpfile | |
title="Subject: $title " | |
echo $title >> $tmpfile | |
echo $title | sed 's/./-/g' >> $tmpfile | |
echo "Category: " >> $tmpfile | |
#echo "Tags: " >> $tmpfile | |
#vim + $tmpfile | |
# takes to end and then appends a line | |
# gd.so has 2 lines "G" and "o" | |
vim -s ~/bin/gd.so $tmpfile | |
echo "" >> $tmpfile | |
echo '* * *' >> $tmpfile | |
text=`cat $tmpfile` | |
ex - $logfile<<! | |
1i | |
$text | |
. | |
x | |
! | |
echo Done | |
echo "++++++" | |
#IFS=$OLDIFS | |
head $logfile | |
echo "Output went to:\n $logfile" | |
#echo "Output went to tempfile:\n$tmpfile" | |
#echo "you may do\\n rm $tmpfile" | |
rm $tmpfile | |
#echo Use log2html.sh to view log in browser. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment