Reputation: 13
So I have this script file that automatically saves the date and time to a file when the terminal is open. But i'm having a hard time putting number lines in it. I tried cat -n, grep -n, ls -l, but I either get errors or doesn't increment. As you can see:
echo $(date) >> .test
I would like to see something like this:
0 : Tue Feb 15 13:10 EST 2014 1 : Tue Feb 18 12:10 EST 2014 2 : Tue Feb 18 10:10 EST 2014 3 : Tue Feb 19 13:22 EST 2014
Upvotes: 1
Views: 58
Reputation: 5225
Here's a solution:
echo $(wc -l < filename) : $(date) >> filename
Upvotes: 1
Reputation: 1789
Try saving the last number in a file. Then, in your script, read in the number, increment it, and write it back to the file. If you are using bash, something like this should work.
num=$(cat number.txt)
num=$(($num+1))
echo $num > number.txt
Upvotes: 0
Reputation: 5072
If you pipe the result into cat
, you can use the -n
option to number each line like so:
ls | grep "whatever" | cat -n
Upvotes: 2