grep 명령어 패턴에 변수를 넣을순 없나요?
글쓴이: dosun99v / 작성시간: 일, 2012/08/19 - 9:36오후
#!/bin/bash user1='dwarp' user2='rush' HOME=/var/log/center cd $HOME if [ -f userinfo.txt ]; then sudo rm userinfo.txt fi for file in * do if [ 'log_' = ${file:0:4} ]; then grep -w 'LOG IN-2 : ['$0078dh']' $file >> userinfo.txt grep 'LOG IN-2 : dwarp' $file >> userinfo.txt fi done
스크립트 작성중 궁금한점이 있어서요
grep [옵션] [패턴] 파일명 이렇게 사용하는데요
grep 두번째 명령어에서 사용자 유저를 dwarp라고 직접 넣어줬느데
첫번째 명령어처럼 유저를 변수로 넣고 싶거든요..ㅠㅠ 잘 안되네요
초보가 여쭈어봅니다 ㅠㅠ
Forums:
grep "LOG IN-2 : ${user1}"
grep "LOG IN-2 : ${user1}" $file >> userinfo.txt
답변 감사합니당^^
꾸벅(_ _)
댓글 달기