sed string replace variable
2014年4月1日 — The shell is responsible for expanding variables. When you use single quotes for strings, its contents will be treated literally, so sed now tries to replace every occurrence of the literal $var1 by ZZ . ,2011年7月19日 — Try this: website=$(sed 's|/|--/|g' <<< $website). Bash actually supports this sort of replacement natively: $parameter/pattern/string} — replace ... ,2018年8月24日 — Unfortunately, this is one of those corners of sed which is poorly standardized. Some variants will absolutely require the newline to be escaped ... ,2012年11月14日 — You are missing the end of that single-quote pair in your script. Change from: echo $SQL | sed -e "s/'$BATCH_END/$BATCH_END/g". To: ,2013年3月6日 — It seems to be that you're trying a combination of piping to sed and using a file. The following will work perfectly fine, sed -i -e ... ,2015年2月17日 — You need to escape your oldline so that it contains no regex special characters, luckily this can be done with sed. old_line=$(echo "$old_line}" ... ,Get rid of the single quotes. They prevent variable expansion. sed "/AXG/s/;/$HOMEx}/g". If HOMEx="test" this becomes: sed "/AXG/s/;/test/g". Compare ... ,2011年10月7日 — Variables inside ' don't get substituted in Bash. To get string substitution (or interpolation, if you're familiar with Perl) you would need to change ... ,1 Answer. Sed is a poor choice if the replacement string is from a variable, because it treats the variable as a sed command and not as literal string, so it will break if the variable contains special characters like / or & or similar. ,2018年2月26日 — That command line would run get_env '-1' in a command substitution, and paste its output on the command line of sed . You should probably ...
相關軟體 PsTools 資訊 | |
---|---|
![]() sed string replace variable 相關參考資料
bash - How do I use variables in a sed command? - Ask Ubuntu
2014年4月1日 — The shell is responsible for expanding variables. When you use single quotes for strings, its contents will be treated literally, so sed now tries to replace every occurrence of the liter... https://askubuntu.com Can I use sed to manipulate a variable in bash? - Stack Overflow
2011年7月19日 — Try this: website=$(sed 's|/|--/|g' <<< $website). Bash actually supports this sort of replacement natively: $parameter/pattern/string} — replace ... https://stackoverflow.com How can i use sed to replace a string with a variable string ...
2018年8月24日 — Unfortunately, this is one of those corners of sed which is poorly standardized. Some variants will absolutely require the newline to be escaped ... https://stackoverflow.com how to replace a variable in shell script string - Stack Overflow
2012年11月14日 — You are missing the end of that single-quote pair in your script. Change from: echo $SQL | sed -e "s/'$BATCH_END/$BATCH_END/g". To: https://stackoverflow.com how to use sed to replace a string in a file with a shell variable ...
2013年3月6日 — It seems to be that you're trying a combination of piping to sed and using a file. The following will work perfectly fine, sed -i -e ... https://stackoverflow.com Replace string variable with string variable using Sed - Stack ...
2015年2月17日 — You need to escape your oldline so that it contains no regex special characters, luckily this can be done with sed. old_line=$(echo "$old_line}" ... https://stackoverflow.com Sed replace string with variable? - Super User
Get rid of the single quotes. They prevent variable expansion. sed "/AXG/s/;/$HOMEx}/g". If HOMEx="test" this becomes: sed "/AXG/s/;/test/g". Compare ... https://superuser.com sed substitution with Bash variables - Stack Overflow
2011年10月7日 — Variables inside ' don't get substituted in Bash. To get string substitution (or interpolation, if you're familiar with Perl) you would need to change ... https://stackoverflow.com Sed, how to replace a string with a variable and string ...
1 Answer. Sed is a poor choice if the replacement string is from a variable, because it treats the variable as a sed command and not as literal string, so it will break if the variable contains specia... https://stackoverflow.com sed: replace strings with variable content - Unix & Linux Stack ...
2018年2月26日 — That command line would run get_env '-1' in a command substitution, and paste its output on the command line of sed . You should probably ... https://unix.stackexchange.com |