Temp file has only the number 22.5 in it.
I use
sed 's/.//' Temp
and I expect 225 but get 2.5
Why?
Temp file has only the number 22.5 in it.
I use
sed 's/.//' Temp
and I expect 225 but get 2.5
Why?
Because '.' is a regular expression that matches any character. You want 's/\.//'
The dot is a special character meaning "match any character".
$ sed s/\\.// temp
225
You would think that you could do sed s/\.// temp
, but your shell will escape that single backslash and pass s/.//
to sed.. So, you need to put two backslashes to pass a literal backslash to sed, which will properly treat \.
as a literal dot. Or, you could quote the command to retain the literal backslash:
$ sed "s/\.//" temp
225
The reason you get 2.5 when you do s/.//
is that the dot matches the first character in the file and removes it.
'.' is special: it matches any single character. So in your case, the sed expression matches the first character on the line. Try escaping it like this:
s/\.//
.
is a wildcard character for any character, so the first character is replaced by nothing, then sed is done.
You want sed 's/\.//' Temp
. The backslash is used to escape special characters so that they regain their face value.