A pedant that hangs out in the dark corner-cases of the web.

Monday, March 12, 2007

Perl one liner: spaces to tabs

This Perl one liner converts a file indented with spaces into one indented with tabs, using the first indented line to measure the number of spaces per indent.

perl -i~ -pe "/^( +)/ or next; $I or $I=$1; for($i=0;s/^$I//;$i++){} $_=(qq'\t' x $i).$_;" file ...

1 comment:

Anonymous said...

Nice post and this enter helped me alot in my college assignement. Say thank you you as your information.