You do not edit lines with grep in a Unix shell, grep usually used to find or remove some lines from text. Instead, you prefer to use sed :
$ echo www.example.com | sed 's/^[^\.]\+\.//' example.com
You need to learn regular expressions in order to use it effectively .
Sed can also edit the file in place (modify the file) if you pass the -i argument, but be careful, you can easily lose data if you write the wrong sed command and use the -i flag.
Example
From your comments, guess that you have a TeX document and you want to delete the first part of all .com domain names. If this is your test.tex document:
\documentclass{article} \begin{document} www.example.com example.com www.another.domain.com \end{document}
then you can convert it using this sed command (redirect the output to a file or edit in-place using -i ):
$ sed 's/\([a-z0-9-]\+\.\)\(\([a-z0-9-]\+\.\)\+com\)/\2/gi' test.tex \documentclass{article} \begin{document} example.com example.com another.domain.com \end{document}
Note:
- The general sequence of allowed characters followed by a period corresponds to
[a-z0-9-]\+\. - I used groups in the regex (parts of it within
\( and \) ) to specify the first and second parts of the URL, and I replaced the whole match with my second group ( \2 in the replacement pattern) - The domain must be at least level 3. COM domain (each
\+ repetition means at least one match) - The search is not case sensitive (
i flag at the end) - In the end, it may correspond more to line (
g )
sastanin
source share