Created
November 27, 2015 08:56
-
-
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.
This file contains hidden or 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 | |
| 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