On Tue, May 03, 2005 at 09:59:47PM -0700, larry price wrote: > On 5/3/05, Jacob Meuser <[EMAIL PROTECTED]> wrote: > > On Tue, May 03, 2005 at 09:15:19PM -0700, Jason Van Cleve wrote: > > > I'd like to process a whole bunch of source files uniformly, stripping > > > off any whitespace at the ends of lines and also making sure there is > > > exactly one newline before the EOF. That last part may be tricky, but > > > is there a speedy *nix utility for getting rid of trailing whitespace, > > > or maybe for general source code processing? > > if you want speed try sed(1) > > s/[\w]*$//g #remove any number of white space characters before end of line > s/^$//g #remove blank lines > > followed by > echo >> $file #append a blank line to the end of the file. > > although if you are getting fancy you might want to rewrite it in perl > or $language > to do manipulation or insertion. > > having done a fair amount of stuff recently that required mucking about with > line end conversions and preprocessing files for a finicky parser > this is where find(1) is your friend > > build your manipulation script and let find pass files to it. > (it's also a good idea to make a copy of the target files before you > munge them so that you can recover from your mistakes while you are > figuring out your regex)
#!/bin/sh set -e : ${CPMV:=mv} FILE="`pwd`/$1" cp ${FILE} ${FILE}.orig sed -e 's,// *\(.*\),/* \1 */,g' ${FILE} > ${FILE}.sed ${CPMV} ${FILE}.sed ${FILE} indent ${FILE} ${FILE}.indent -di8 -dj0 -nfc1 -i4 ${CPMV} ${FILE}.indent ${FILE} exit 0 -- <[EMAIL PROTECTED]> _______________________________________________ EUGLUG mailing list euglug@euglug.org http://www.euglug.org/mailman/listinfo/euglug