hey
if i have a variable that is
example=lewisdenny(copywrite symbol)
so its not a nomal letter but a symbol, how can i remove everything in the varible that isnt letter or number thanks
and as a side little question do you know how to remove .zip from a file like if i
ls /temp
test.zip
how can i remove the .zip and set it as a varable like this?
example=$(ls /temp | grep (command to remove .zip)
thanks
Remove numbers and letters
variable=$(printf "$variable" | sed 's/[0-9a-zA-Z]//g')
Remove zip extension
variable=$(printf "$variable" | sed 's/\.zip$//g')
You can try % or %%. ${variable%%.*}
Not in all shells:
variable=${variable/%\.zip}
---------- Post updated at 11:53 AM ---------- Previous update was at 11:49 AM ----------
What you're looking for:
example=$(ls /temp | sed 's/\.zip$//')
thanks for the answers but im trying to remove everything BUT the letters and numbers
Sorry lad, I was almost sleeping!!! Hahaha
---------- Post updated at 01:09 PM ---------- Previous update was at 12:54 PM ----------
This leaves only the letters and numbers (removes �...):
$ example=lewisdenny�
$ echo $example
lewisdenny�
$ example=$(printf "$example" | sed 's/[^0-9a-zA-Z]//g')
$ echo $example
lewisdenny
1 Like
You could also use the POSIX character class "[:alnum:]" like so -
$
$ echo $str
lewisdenny�
$
$ str=$(echo $str | sed 's/[^[:alnum:]]//g')
$
$ echo $str
lewisdenny
$
$
tyler_durden
thanks thats just what i wanted