Avoid a process spawn in trim function

no more call of sed, use of bash internals.