Created
          December 8, 2020 21:26 
        
      - 
      
 - 
        
Save rodrigodev/e4dc6d5c654969a7e6492a97603e503b to your computer and use it in GitHub Desktop.  
    Convert encoding batch for Mac OS
  
        
  
    
      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 | |
| #enter input encoding here | |
| FROM_ENCODING="ISO_8859-1" | |
| #output encoding(UTF-8) | |
| TO_ENCODING="UTF-8" | |
| #convert | |
| CONVERT="iconv -f $FROM_ENCODING -t $TO_ENCODING" | |
| #loop to convert multiple files | |
| for file in ./*.txt; do | |
| encoding=$(file -I "$file" | awk '{print $3}') | |
| if [ "$encoding" == "charset=iso-8859-1" ]; then | |
| $CONVERT "$file" >"$file.new" && | |
| mv -f "$file.new" "$file" | |
| fi | |
| done | |
| exit 0 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment