string-substitution

How to use Bash parameter substitution in a Makefile?

北城以北 提交于 2019-11-29 18:39:09
I've the following Makefile where I'd like to use Bash parameter substitution syntax as below: SHELL:=/bin/bash Foo=Bar all: @echo ${Foo} @echo ${Foo/Bar/OK} However it doesn't work as expected, as the output of the second echo command is empty: $ make Bar (empty) Although it works fine when invoking in shell directly: $ Foo=Bar; echo ${Foo/Bar/OK} OK How can I use the above syntax in Makefile? If you want the shell to expand the variable you have to use a shell variable, not a make variable. ${Foo/Bar/OK} is a make variable named literally Foo/Bar/OK . If you want to use shell variable

Substitution of characters limited to part of each input line

梦想与她 提交于 2019-11-29 16:45:30
Have a file eg. Inventory.conf with lines like: Int/domain—home.dir=/etc/int I need to replace / and — before the = but not after. Result should be: Int_domain_home_dir=/etc/int I have tried several sed commands but none seem to fit my need. SLePort Sed with a t loop (BRE): $ sed ':a;s/[-/—.]\(.*=\)/_\1/;ta;' <<< "Int/domain—home.dir=/etc/int" Int_domain_home_dir=/etc/int When one of the -/—. character is found, it's replaced with a _ . Following text up to = is captured and output using backreference. If the previous substitution succeeds, the t command loops to label :a to check for further

How to use Bash parameter substitution in a Makefile?

回眸只為那壹抹淺笑 提交于 2019-11-28 12:05:55
问题 I've the following Makefile where I'd like to use Bash parameter substitution syntax as below: SHELL:=/bin/bash Foo=Bar all: @echo ${Foo} @echo ${Foo/Bar/OK} However it doesn't work as expected, as the output of the second echo command is empty: $ make Bar (empty) Although it works fine when invoking in shell directly: $ Foo=Bar; echo ${Foo/Bar/OK} OK How can I use the above syntax in Makefile? 回答1: If you want the shell to expand the variable you have to use a shell variable, not a make

Substitution of characters limited to part of each input line

拜拜、爱过 提交于 2019-11-28 10:49:17
问题 Have a file eg. Inventory.conf with lines like: Int/domain—home.dir=/etc/int I need to replace / and — before the = but not after. Result should be: Int_domain_home_dir=/etc/int I have tried several sed commands but none seem to fit my need. 回答1: Sed with a t loop (BRE): $ sed ':a;s/[-/—.]\(.*=\)/_\1/;ta;' <<< "Int/domain—home.dir=/etc/int" Int_domain_home_dir=/etc/int When one of the -/—. character is found, it's replaced with a _ . Following text up to = is captured and output using

Replace specific characters within strings

馋奶兔 提交于 2019-11-26 03:15:14
问题 I would like to remove specific characters from strings within a vector, similar to the Find and Replace feature in Excel. Here are the data I start with: group <- data.frame(c(\"12357e\", \"12575e\", \"197e18\", \"e18947\") I start with just the first column; I want to produce the second column by removing the e \'s: group group.no.e 12357e 12357 12575e 12575 197e18 19718 e18947 18947 回答1: With a regular expression and the function gsub() : group <- c("12357e", "12575e", "197e18", "e18947")