sed + removes all leading and trailing whitespace from each line on solaris system

awk, perl, sed, solaris

Solution

Just occurred to me you can use a character class:

sed 's/^[[:space:]]*//;s/[[:space:]]*$//'

This happens in your `sed` and gnu sed with the `--posix` option because (evidently) posix interprets the `[ \t]` as a space, a `\`, or a `t`. You can fix this by putting a literal tab instead of `\t`, easiest way is probably Ctrl+V Tab. If that doesn't work, put the patterns in a file (with the literal tabs) and use `sed -f patterns.sed oldfile > newfile`.

Problem

I have a Solaris machine (SunOSsu1a 5.10 Generic_142900-15 sun 4vsparcSUNW,Netra-T2000). The following sed syntax removes all leading and trailing whitespace from each line (I need to remove whitespace because it causes application problems). ``` sed 's/^[ \t]*//;s/[ \t]*$//' orig_file > new_file ``` But I noticed that sed also removes the "t" character from the end of each line. Please advise how to fix the sed syntax/command in order to remove only the leading and trailing whitespace from each line (the solution can be also with Perl or AWK). Examples (take a look at the last string - set_host) 1) Original line before running sed command ``` pack/configuration/param[14]/action:set_host ``` another example (before I run sed) ``` +/etc/cp/config/Network-Configuration/Network-Configuration.xml:/cp-pack/configuration/param[8]/action:set_host ``` 2) the line after I run the sed command ``` pack/configuration/param[14]/action:set_hos ``` another example (after I run sed) ``` +/etc/cp/config/Network-Configuration/Network-Configuration.xml:/cp-pack/configuration/param[8]/action:set_hos ```

Original source