How to rewrite common prefix as header?
Say you're having a list of change notes like this:
2011-02-21: Removed first feature to get rid of previous customer
2011-02-21: Added second feature to open up new markets
2011-02-09: Implemented hot fix to calm down angry customer
2011-02-08: Developed project into a minimal viable product
2011-02-08: Started project
Can this be rewritten into the following format using standard shell tools?
2011-02-21
* Removed first feature to get rid of previous customer
* Added second feature to open up new markets
2011-02-09
* Implemented hot fix to calm down a开发者_StackOverflowngry customer
2011-02-08
* Developed project into a minimal viable product
* Started project
If so, how?
Pipe through this.
#!/bin/bash
lastprefix=""
while read prefix line
do
if [ "$prefix" != "$lastprefix" ]
then
lastprefix="$prefix";
echo ""
echo "$prefix"
fi
echo " * $line"
done
This should do it:
awk -F: '$1 != prev {print $1; prev = $1} {$1 = ""; print " *" $0}' inputfile
精彩评论