How should i use sed command to replace a pattern of multiple occurrences with space. how to make this text -asadjh--nfkdjnf------nfjksnfjkd as <space>asadjh<space> nfkdjnf<space>nfjksnfjkd
Thanks in advance!
How should i use sed command to replace a pattern of multiple occurrences with space. how to make this text -asadjh--nfkdjnf------nfjksnfjkd as <space>asadjh<space> nfkdjnf<space>nfjksnfjkd
Thanks in advance!
Try:
sed 's/-+/ /g' file
echo '-asadjh--nfkdjnf------nfjksnfjkd'|tr -s '-' ' '
Could someone with sed knowledge clear up why this is the case?
skrynesaver@busybox:~$ echo '-asadjh--nfkdjnf------nfjksnfjkd'|perl -e '$_=<STDIN>; s/(.)\1+/ /g;print'
-asadjh nfkdjnf nfjksnfjkd
skrynesaver@busybox:~$ echo '-asadjh--nfkdjnf------nfjksnfjkd'|sed 's/\(.\)\1+/ /g'
-asadjh--nfkdjnf------nfjksnfjkd
Hmmn sed -r works correctly (GNU sed)
In GNU Sed you would need to escape the sign + in order to work.