regular expression
Dear all,
Is it possible to replace "\" with "blank space" using sed. thanks |
Quote:
. Oh!!!--did you mean to ask HOW?? The trick here is that any character can be used as the separator in the SED "s" (substitute) construct. So, just use this general form: sed 's#old#new#' (add a "g" to make it replace all "old" with "new".) old or new can now contain the "/". The other method is to escape the "/" so that it is not interpreted as a separator. eg use "\/" to get a literal "/". OOPS--I read "/" instead of "\"---see below. |
I used the following,
linux ~]# echo "this is\ test" | sed 's#\#windows#' sed: -e expression #1, char 12: unterminated `s' command linux ~]# echo "this is\ test" | sed 's#test#windows#' this is\ windows the first one outputs error, whereas if any other charcter it replaces successfuly. :( |
You can use awk. make the input delimiter as "\" , then set output field delimiter as null
Code:
# echo "this is\ test" | awk -F'\' '{$1=$1;}1' OFS="" |
In sed "\\" represents a literal "\"
Code:
echo "this is\ test" | sed 's/\\/windows/' |
Sorry--I misread the original post.
Any character which normally has a special meaning has to be escaped. "/" only has special meaning in the "s" command when it is used as the delimiter. "\" is always special unless escaped. |
All times are GMT -5. The time now is 08:16 AM. |