Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove all occurences of dot in a string in a shell script?

Tags:

linux

shell

e.g hostname = "test.test.test", then after removing result should be like "testtesttest"

like image 954
rupali Avatar asked Dec 02 '10 06:12

rupali


People also ask

How do I remove a character from a string in shell script?

The tr command (short for translate) is used to translate, squeeze, and delete characters from a string. You can also use tr to remove characters from a string. For demonstration purposes, we will use a sample string and then pipe it to the tr command.

How do you escape a dot in shell script?

The commandline is interpreted by the shell, using the first \ to escape the second one, so one \ is passed literally to grep. The dot . is not special to the shell, so it is passed verbatim anyway. Grep then reads the (single) \ and uses it to escape the dot . .

How do I cut a string after a specific character in bash?

In Bash (and ksh, zsh, dash, etc.), you can use parameter expansion with % which will remove characters from the end of the string or # which will remove characters from the beginning of the string. If you use a single one of those characters, the smallest matching string will be removed.

What does ${} mean in shell script?

Here are all the ways in which variables are substituted in Shell: ${variable} This command substitutes the value of the variable. ${variable:-word} If a variable is null or if it is not set, word is substituted for variable.


2 Answers

$ foo=test.test.test $ echo "${foo//./}" testtesttest 
like image 129
Ignacio Vazquez-Abrams Avatar answered Sep 22 '22 23:09

Ignacio Vazquez-Abrams


You can also pipe into

tr -d '.' 

But the best way of doing this is not to use an external command and use shell built in.

like image 38
codaddict Avatar answered Sep 21 '22 23:09

codaddict