bash - Replace 5 dots with a single space -


i have title has 5 consecutive dots i'd replaced 1 space using bash script. doing not helping:

tr '.....' ' '  

obviously because it's replacing 5 dots 5 spaces.

basically, have title want changed slug. i'm using:

tr a-z a-z | tr '[:punct:] [:blank:]' '-' 

to change lowercase , change punctuation mark , spaces hyphen, i'm stuck dots.

the title i'm using like: believe.....right now

so want turned believe-right-now

how change 5 dots single space?

you don't need sed or awk. original tr command should trick, need add -s flag. after tr translates desired characters hyphens, -s squeeze repeated hyphens one:

tr a-z a-z | tr -s '[:punct:] [:blank:]' '-' 

i'm not sure input/output context you, tested above follows, , worked me:

tr a-z a-z <<< "believe.....right now" | tr -s '[:punct:] [:blank:]' '-' 

output:

believe-right-now

see http://www.ss64.com/bash/tr.html reference.


Comments

Popular posts from this blog

vb.net - Alternative to the T-SQL AS keyword -

php - MySQLi binding parameters in a prepared statement doesn't work unless inserted after "WHERE" -

ios - CFRelease causing crash in iPad application -