Skip to content

Instantly share code, notes, and snippets.

@Hinidu
Created May 8, 2014 11:20
Show Gist options
  • Save Hinidu/556ebec2c80917ae96c5 to your computer and use it in GitHub Desktop.
Save Hinidu/556ebec2c80917ae96c5 to your computer and use it in GitHub Desktop.
#!/bin/sh
function process_file() {
[ -z "$FILE" -o -z "$RANGES" ] && return 0
echo -e $RANGES | sed 's/-/,/' | sort -nr | while read RANGE
do
sed -i $RANGE"d" $FILE
done
FILE=""
RANGES=""
}
FILE=""
while read LINE
do
if echo $LINE | grep -q "should remove"
then
process_file
FILE=`echo $LINE | sed 's/ should remove.*//'`
echo $FILE
fi
if echo $LINE | grep -q "^- .*"
then
echo $LINE
RANGE=`echo $LINE | sed 's/^.* lines //'`
[ -n "$RANGES" ] && RANGES="$RANGES\n"
RANGES="$RANGES$RANGE"
fi
done
process_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment