Rohan G Rohan G - 2 months ago 7x
Bash Question

How to extract text from a particular point in string using sed?

I want to break single string into two different strings using


For eg:

STRING := folder1_test.abc_xxx

STRING1 := folder1_test

STRING2 := abc_xxx


STRING := folderB_test folderA_test.yyyy_xx

STRING1 := folderB_test folderA_test

STRING2 := yyyy_xx

So whatever is before dot(.) I want in first string and after dot(.) I want that thing in second string.

Specifically with
command only. As I am using in makefile implementation.


From your post I understand that you need this in a Makefile (and the syntax is confirming this). In that case this is what you need:

For example:
STRING1 := $(firstword $(subst ., ,$(STRING)))
STRING2 := $(or $(word 2,$(subst ., ,$(STRING))),$(value 2))