5 Replies Latest reply on Nov 19, 2012 6:57 AM by John Landells

    Pulling my hair out with sed!!!

      Hi All,

       

      I need to have part of my code strip any blank characters (space, tab, newline, carriage-return, etc) from a variable.  Under Bash, I can do something like this:

       

      TEST="                              This is a simple test with whitespace at both ends - should be a trivial test!                 "

      TRIMMED=`echo "$TEST" | sed -e 's/^\s*//' | sed -e 's/\s*$//'`

      echo ">$TRIMMED<"

       

      which under Bash, happily prints:

       

      >This is a simple test with whitespace at both ends - should be a trivial test!<

       

      However, under NSH I get:

       

      >                              This is a simple test with whitespace at both ends - should be a trivial test!                 <

       

      Sure, I can replace the "\s" with " " and it will work in this case, but even changing it to "[ \t]" makes it fail!

       

      I'm sure I'm missing something simple, but I can't see it!  Can anyone help, please?

       

      Many thanks,

      -John.