Rohan G Rohan G - 4 months ago 11
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

sed
.

For eg:

STRING := folder1_test.abc_xxx

STRING1 := folder1_test

STRING2 := abc_xxx

or

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
sed
command only. As I am using in makefile implementation.

Answer

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: http://stackoverflow.com/a/8540718/3464942

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

Comments