linux 에서 sed 로 문서파일을 편집/치환할 수 있잖아요.
그런데 가령 'hellow' hellow -> 'love' heelow 로 치환 할때
sed -e 's/'\'hellow\'/\'love\'/g' -i data.txt
로 하면 애러가 나던데 중간에 '(single quta) 를 escape 처리할려면 어떻게 해야 하나요?
알려주시면 감사하겠습니다.
전체를 작은따옴표 대신 큰따옴표로 묶으세요.
$ cat data.txt 'hellow' hellow $ sed -e "s/'hellow'/'love'/g" -i data.txt $ cat data.txt 'love' hellow
스크립트 부분에 큰따옴표 작은따옴표 둘 다 들어갈 때가 제일 헷갈리는데, 저도 늘 끙끙대가 지금 찾아보니 \x27 이라고 써도 되나보네요.https://stackoverflow.com/a/24509931/1150133
좋은 하루 되세요!
sed 에 들어가는 스크립트 앞에 $ 를 넣어줘도 됩니다.
$ echo "'hellow' hellow" | sed $'s/\'hellow\'/\'love\'/g' 'love' hellow
되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』
$를 작은따옴표 앞에 붙이는 것이 어떤 의미인지 몰라서 찾아봤습니다.ANSI-C Quoting 이라고 부르는군요. ( https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html#ANSI_002dC-Quoting )
ANSI-C Quoting Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard
Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard
잘 배워 갑니다. 저처럼 몰랐던 분들께 참고가 될 것 같아 덧글 달아둡니다.
음...
이경우엔 그냥 쌍따옴표 써도 되는군요.
$ cat data.txt 'hellow' hellow $ sed "s/'hellow'/'love'/g" < data.txt 'love' hellow
텍스트 포맷에 대한 자세한 정보
<code>
<blockcode>
<apache>
<applescript>
<autoconf>
<awk>
<bash>
<c>
<cpp>
<css>
<diff>
<drupal5>
<drupal6>
<gdb>
<html>
<html5>
<java>
<javascript>
<ldif>
<lua>
<make>
<mysql>
<perl>
<perl6>
<php>
<pgsql>
<proftpd>
<python>
<reg>
<spec>
<ruby>
<foo>
[foo]
전체를 작은따옴표 대신 큰따옴표로 묶으세요.
전체를 작은따옴표 대신 큰따옴표로 묶으세요.
스크립트 부분에 큰따옴표 작은따옴표 둘 다 들어갈 때가 제일 헷갈리는데, 저도 늘 끙끙대가 지금 찾아보니 \x27 이라고 써도 되나보네요.
https://stackoverflow.com/a/24509931/1150133
좋은 하루 되세요!
음 ..
sed 에 들어가는 스크립트 앞에 $ 를 넣어줘도 됩니다.
되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』
$를 작은따옴표 앞에 붙이는 것이 어떤 의미인지
$를 작은따옴표 앞에 붙이는 것이 어떤 의미인지 몰라서 찾아봤습니다.
ANSI-C Quoting 이라고 부르는군요.
( https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html#ANSI_002dC-Quoting )
잘 배워 갑니다.
저처럼 몰랐던 분들께 참고가 될 것 같아 덧글 달아둡니다.
음...
음...
이경우엔 그냥 쌍따옴표 써도 되는군요.
댓글 달기