How to clear code base, trailing spaces, newlines, etc.

I have a code base that makes me run into conflicts due to lagging spaces. I would like to clean it.

I want to:

  • Delete all trailing spaces
  • Delete newlines at the end of files
  • Convert all strings to unix (dos2unix)
  • Convert all leading spaces to tabs i.e. 4 spaces to tabs.

  • When ignoring the .git directory.

I am on OSX Snow Leopard and zsh .

so far I:

sed -i "" 's/[ \t]*$//' **/*(.)

which works fine, but sed adds a new line at the end of every file it touches, which is not good. I don’t think sed can be stopped from doing this, so how can I delete these new lines? Maybe there is some kind of awk magic here.

(Full answers are also welcome)

+5
1

[: ​​ ]
[ # 2: ]

perl -i.bak -pe 'if (defined $x && /\S/) { print $x; $x = ""; } $x .= "\n" x chomp; s/\s*?$//; 1 while s/^(\t*)    /$1\t/; if (eof) { print "\n"; $x = ""; }' **/*(.)

, \n . , . , \n, print "\n"; .

"" \n , , , - .

.bak, ( !)

\s*? , , \r, \r\n DOS. Perl $ , \n, , *? - ( 0, 1- width match ..), .

1 while s/^(\t*) /$1\t/ - , , , 4 , , , , . , , , \t , 4.

**/*(.) , , zsh? sed, perl.

+5

All Articles