Last active
          December 11, 2015 07:28 
        
      - 
      
- 
        Save restrepo/4566188 to your computer and use it in GitHub Desktop. 
    REGEX raplacement in a list of files
  
        
  
    
      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
    
  
  
    
  | #!/usr/bin/env bash | |
| pattern=$1 | |
| replace=$2 | |
| list=$3 | |
| if ! [ $replace ]; then | |
| echo USAGE: $0 PATTERN REPLACEMENT LIST | |
| echo EXAMPLE: $0 \""R-\\([a-z]\\+\\)"\" \"\\\$R\\\$-"\1"\" \"\*.tex\" | |
| fi | |
| for i in $list; do | |
| sed 's/'"$pattern"'/'"$replace"'/g' $i > /tmp/tmpfile | |
| if [ $(diff $i /tmp/tmpfile| wc -l) -gt 0 ]; then | |
| mv /tmp/tmpfile $i | |
| fi | |
| done | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment