Den 2011-02-18 13:12 skrev Peter Rosin: > Yes, I will try my best not to spam the list with more versions of > this baby...
Famous last words. Sorry. 18 lines -> 15 lines -> 12 lines Will be AFK the next week, so with a bit of luck I will have forgotten all about this when I get back. Cheers, Peter (who is aware that comments in sed programs are not portable -> strip) unindent () { sed ' /^$/b # Nothing to do for empty lines, next line please. x # Get x<indent> into pattern space. /^$/{ # No prior x<indent>, go prepare it. g # Copy this 1st non-blank line into pattern space. s/^\([ ]*\).*/x\1/ # Prepare x<indent> in pattern space. } # Now: x<indent> in pattern and <line> in hold. G # Build x<indent>\n<line> in pattern space, and h # duplicate it into hold space. s/\n.*$// # Restore x<indent> in pattern space, and x # exchange with the above duplicate in hold space. s/^x\(.*\)\n\1// # Remove leading <indent> from <line>. s/^.*\n//' # Restore <line> when there's no leading <indent>. }