Posted By

deepsoul on 08/07/09


Tagged

edit filter overwrite in-place


Versions (?)

Filter files in place


 / Published in: Bash
 

URLs: http://www.chiark.greenend.org.uk/~sgtatham/utils/ http://kitenet.net/~joey/code/moreutils/

Use one of these nifty utilities to automatically process files in-place. Both store the results of programs which write to stdout until they are done, and then write the result. See also sed's -i option. Be aware that this may clobber your files if an error occurs during processing, so it is best to back them up (though reservoir refuses to truncate files to nothing by default).

  1. # Example 1: capitalisation
  2. tr a-z A-Z < xy.txt | reservoir -o xy.txt
  3. tr a-z A-Z < xy.txt | sponge xy.txt
  4.  
  5. # Example 2: evaluate #ifdefs of all C files in directory
  6. # unifdef is from http://dotat.at/prog/unifdef/
  7. # MAKE A BACKUP BEFORE RUNNING THIS LOOP, YOUR FILES WILL BE OVERWRITTEN!
  8. find . -iname \*.c | while read file ; do unifdef $file | reservoir -o $file ; done

Report this snippet  

You need to login to post a comment.