strings – Bash. Extract substring

Question:

The variable contains a value of the "текст1:текст2" .

How do I get the part of this line after the colon?

Answer:

You can take parts of lines in bash without using external commands:

$ v="текст1:текст2"
$ echo ${v%:*} # убрать всё после последнего двоеточия
текст1
$ echo ${v#*:} # убрать всё до первого двоеточия
текст2
Scroll to Top