글쓴이: 익명 사용자 / 작성시간: 금, 2002/12/06 - 2:23오후
bash에서 스크립트를 짜려고 합니다.
하나의 인자를 받아서 인자의 문자열에 공백문자나 -가 있으면 _로 변환
하려고 합니다. 어떻게 해야 하나요?
php파일중에 이렇게 하는게 있던데
$s_file_name1=str_replace(" ","_",$s_file_name1);
$s_file_name1=str_replace("-","_",$s_file_name1);
그냥 bash에서 하는 방법은 없나요?
감사합니다.
Re: 문자열변환
sed 를 이용하면 됩니다.
[root@localhost /root]# sed -e s/" "/"_"/g
he ll o
he_ll_o
Re^2: 문자열변환
감사합니다.
전 이렇게 해결하였습니다.
t=he\ llo
f=${t//\ /_}
final=${f//-/_}
echo $t
echo $final
----------------
he llo
le_llo
----------------
sed는 좀 어려운거 같네요.. 감사합니다. sed공부도 해봐야 겠어요.
감기조심하세요..
댓글 달기