Skip to content

Instantly share code, notes, and snippets.

@niltonvasques
Created November 27, 2015 08:56
Show Gist options
  • Select an option

  • Save niltonvasques/143f4c6d796303ee9295 to your computer and use it in GitHub Desktop.

Select an option

Save niltonvasques/143f4c6d796303ee9295 to your computer and use it in GitHub Desktop.
Remove one line following a pattern in many files, and open vimdiff to confirm.
#!/bin/bash
confirm () {
# call with a prompt string or use a default
read -r -p "${1:-Are you sure? [y/N]} " response
case $response in
[yY][eE][sS]|[yY])
true
;;
*)
false ;;
esac
}
for i in $(ls | cut -f1 -d. | awk '{ split($0,a,"_controller"); print a[1] }'); do
line=$(grep @$i -n -R . | grep where | grep ^./$i'_controll');
number=$(echo $line | cut -f2 -d: | cut -f1 -d:)
file=$(echo $line | cut -f1 -d:)
param=$number"d"
#echo $number $file
if [ ! -n "$number" ]
then
echo empty
else
echo $number
vimdiff <(sed $param $file) $file
if( confirm )
then
sed $param $file > tmpfile; mv tmpfile $file
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment