[sed/error] sed -i ์ฌ์ฉ ์, ๋ฐ์ํ๋ unterminated substitute in regular expression / undefined label / extra characters at the end of l command ์ค๋ฅ
๋ฌธ์ ์ํฉ
blue-green ๋ฐฐํฌ ๊ตฌํ์ ์ํด nginx์ default.conf ํ์ผ์ ์์ ํ๋ ๊ณผ์ ์์, sed -i ๋ช ๋ น์ด๋ฅผ ์ฌ์ฉํ๋ค.
sed -i [suffix]
sed๋ stream editor์ ์ฝ์๋ก ํ์ค ์ ๋ ฅ ๋๋ ํ์ผ์์ ์ค๋ ํ ์คํธ์ ๋ํ ํธ์ง ์์ ์ ์ํํ๋ค. ์ด๋ -i ์ต์ ์ ํ์ค ์ถ๋ ฅ์ด ์๋ ํ์ผ์ ํธ์งํ๊ธฐ ์ํด ์ฌ์ฉํ๋ค.
sed -i 's/{๋ณ๊ฒฝ์ ๋ฌธ์์ด}/{๋ณ๊ฒฝํ๋ฌธ์์ด}/g' file
์ ๋ช ๋ น์ suffix๋ ์์ฑํ์ง ์๊ณ , ๋ถ์ ๋ช ๋ น์ผ๋ก s, ํ๋๊ทธ๋ g๋ฅผ ์ฌ์ฉํด, ํ์ผ ์์ ํน์ ๋ฌธ์๋ฅผ ์ ๋ถ ์นํํ๊ณ ์ ํ๋ค. ํ์ง๋ง ์ ๋ช ๋ น์ด๋ ๋ฆฌ๋ ์ค ์๋ฒ์์๋ ์ ์๋ํ์ง๋ง, ๋งฅ ์๋ฒ์์ ์ค๋ฅ๋ฅผ ๋ฐํํ๋ค. (ํน์ ์ค๋ฅ๊ฐ ๋๊ธฐ ๋ณด๋ค๋ ์ํฉ์ ๋ฐ๋ผ ์ฌ๋ฌ ์ค๋ฅ๊ฐ ๋.)
sed: 1: "nginx/default.conf": unterminated substitute in regular expression
sed: 1: "default.conf": undefined label 'efault.conf’
๊ฒ์ํด๋ณด๋ ์๋์ ๊ฐ์ ์ค๋ฅ๊ฐ ๋๊ธฐ๋ ํ๋ค.
sed: 1: "/path/to/file.txt": extra characters at the end of l command
ํด๊ฒฐ ๊ณผ์
MacOS์ Linux์์ sed๋ ๋ค๋ฅธ ๋ฒ์ ์ ๊ฐ์ง๋ค, ๋ฐ๋ผ์ i์ ๊ฒฝ์ฐ ์๋์ ๊ฐ์ด ์ฌ์ฉํด์ผ ํ๋ค
GNU(Linux์ ํ์ค) sed์ ๊ฒฝ์ฐ
sed -i 's/{๋ณ๊ฒฝ์ ๋ฌธ์์ด}/{๋ณ๊ฒฝํ๋ฌธ์์ด}/g' file
BSD/MacOS sed์ ๊ฒฝ์ฐ
sed -i '' 's/{๋ณ๊ฒฝ์ ๋ฌธ์์ด}/{๋ณ๊ฒฝํ๋ฌธ์์ด}/g' file
Sed -i์ ์๋ ๊ณผ์
sed -i๋ ํ์ค ์ถ๋ ฅ์ด ์๋๋ผ ๋ด๋ถ์์ ์์ ํ์ผ์ ๋ด์ฉ์ ์ถ๋ ฅํ๋ค. ์ถ๋ ฅ์ด ๋๋๋ฉด, ์์ ํ์ผ ์ด๋ฆ์ ์๋ณธ ํ์ผ์ ์ด๋ฆ์ผ๋ก ๋ฐ๊พผ๋ค. ์ด๋ suffix๊ฐ ์์ผ๋ฉด, ์์ ํ์ผ์ ์ด๋ฆ์ด ๋ฐ๋๊ธฐ ์ ์, ์๋ณธ ํ์ผ ์ด๋ฆ์ suffix๋ฅผ ํ์ฅ์๋ก ํด ๋ฐฑ์ ์ฌ๋ณธ์ ๋ง๋ ๋ค.
์ด๋ GNU sed๋ suffix๊ฐ ์ ํ, BSD sed๋ ํ์์ด๋ค!
suffix๋ฅผ ๋ฐฑ์ ํ์ผ์ ํ์ฅ์์ธ .bak๋ก ์ค์ ํด ๋ฐฑ์ ํ์ผ์ ๋ง๋ค์ด๋ณด์.
GNU๋ -i.bak , BSD๋ -i.bak, -i .bak ๋ฅผ ์ฌ์ฉํ ์ ์๋ค.
๋ง์ฝ์ suffix๋ฅผ ์ง์ ํด์ฃผ์ง ์์ผ๋ฉด, ๋ฐฑ์ ์ ๋ง๋ค์ง ์๊ณ ์๋ณธ ํ์ผ์ ๋ฎ์ด์ด๋ค.
GNU๋ -i ๋ง ์ฌ์ฉํด์ค๋ ๋์ง๋ง, BSD๋ -i '' ์ ๊ฐ์ด ๋น ๋ฌธ์์ด์ ํ์์ ์ผ๋ก ์ฌ์ฉํด์ค์ผ ํ๋ค. ์ด๋ ๋์ด์ฐ๊ธฐ์ ์ ์ํ์.
๋งฅ๊ณผ ๋ฆฌ๋ ์ค๋ฅผ ํธํํ๊ธฐ ์ํด์, Mac์์ gnu sed๋ฅผ ๊ธฐ๋ณธ์ผ๋ก ์ฌ์ฉํ๊ฒ ๋ค๋ ์ค์ ์ ํด์ฃผ๊ฑฐ๋
brew install gnu-sed --with-default-names
์กฐ๊ฑด๋ฌธ์ ํตํด์ os์ ๋ฐ๋ผ, ๋ช ๋ น์ด๋ฅผ ๋ค๋ฅด๊ฒ ์ง์ ํด์ฃผ๋ ๊ฒ๋ ๋ฐฉ๋ฒ์ด ๋ ์ ์๋ค.
์ถ์ฒ
sed command with -i option (in-place editing) works fine on Ubuntu but not Mac
I know nothing about Sed but need this command (which works fine on Ubuntu) to work on a Mac OSX: sed -i "/ $domain .*#drupalpro/d" /etc/hosts I'm getting: sed: 1: "/etc/hosts": extra characters...
stackoverflow.com
sed, a stream editor
sed uses the POSIX basic regular expression syntax. According to the standard, the meaning of some escape sequences is undefined in this syntax; notable in the case of sed are \|, \+, \?, \`, \', \<, \>, \b, \B, \w, and \W. As in all GNU programs that use
www.gnu.org