'linux'에 해당되는 글 4건

  1. 2016.04.11 UPT 15장 와일드 카드- 보다는 grep만.
  2. 2016.03.04 [linux command ] which, whereis
  3. 2016.03.04 [linux command] mkdir -p -m
  4. 2016.03.04 [linux command] cut

grep -l '검색어' *


결과값

host_id

makeFormat.pl

new_userlist

newlog


이런식이라고 가정한다면, 검색어가 파일 내에 존재하는 모든 파일의 이름이 출력된다. 

파일명을 저장해놓고 해당 파일에 대해서만 명령을 수행할 수 있는 장점이 있다. 


$grep -c '검색어' *.log


결과 값

1551user:0

host_id:20

makeFormat.pl:1

new_userlist:20

newlog:40

result_cat:0

user:0


즉 해당 파일에 몇번이나 해당 검색어가 포함되었는지 알 수 있다. 

이 중에서 :0 을 제외해서 필요한 내용만 사용할 수 있다. 

'Unix Power Tools' 카테고리의 다른 글

pushd <-> popd  (0) 2016.04.06
[UPT] 12.01 효율적인 작업 제어  (0) 2016.03.21
Posted by 썬,더 호글
,

명령어의 위치를 알고 싶다면 which를 사용할 수 있다. 

단점은 path에서 처음 발견된 which에 관한 위치만 나온다는 점이다. 

이를 보완하고 싶을 경우 -a 옵션을 주면 해당하는 모든 위치가 나온다. 


~/test/shPractice which grep

grep: aliased to grep  --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn}

~/test/shPractice which -a grep

grep: aliased to grep  --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn}

/usr/bin/grep


 whereis는  명령어의 실행파일위치, 소스위치, man 페이지파일의 위치를 찾아주는 명령어라고 한다. (출처: http://webdir.tistory.com/158)



'배운 것' 카테고리의 다른 글

perl로 날짜 비교 하기  (0) 2016.03.28
holder pattern in java  (0) 2016.03.15
[linux command] mkdir -p -m  (0) 2016.03.04
[linux command] cut  (0) 2016.03.04
git 명령어 alias 를 이용해서 짧게 쓰기  (0) 2016.03.03
Posted by 썬,더 호글
,

~/test/shPractice mkdir -p ./test/test2/test3


~/test/shPractice cd test/test2/test3/



-p 옵션은 parent 옵션.mkdir 을 할 때 실제로 존재하지 않는 디렉토리가 확인될 경우 생성해준다. 


~/test/shPractice mkdir -m 755 /test/testtest/testtesttest   


-m 옵션은 보호 모드를 설정해서 디렉토리를 순차적으로 생성해준다. 




'배운 것' 카테고리의 다른 글

holder pattern in java  (0) 2016.03.15
[linux command ] which, whereis  (0) 2016.03.04
[linux command] cut  (0) 2016.03.04
git 명령어 alias 를 이용해서 짧게 쓰기  (0) 2016.03.03
byte[] 를 String으로 읽어들일 때  (0) 2016.02.01
Posted by 썬,더 호글
,

[linux command] cut

배운 것 2016. 3. 4. 21:59

cut -d /; -f 3,4 text.log


cut 명령어에서 


- d, --delimeter와 같아. 뒤에 나오는 캐릭터로 문자열을 배열 형태로 파싱한다. 

- 위의 예시에서 세미콜론 앞에 역슬래쉬가 붙어있는 이유는 파싱 기준이 세미콜론이라서. (명령어 종료로 인식)

- -f 는  cut -d의 결과로 나온 배열의 field를 의미. -f 3 하면 3번째 필드가, -f 3,4 하면 3번째, 4번째 필드가 출력된다. 

- 단, 이 필드의 순번은 0 이 아니라 1번부터 시작한다. 싱-기-




+덧붙임


7117  cat error_json_2016-06-08.log|cut -d ;     (실패)

 7118  cat error_json_2016-06-08.log|cut -d;    (실패)

 7119  cat error_json_2016-06-08.log|cut -d\;    (실패)

usage: cut -b list [-n] [file ...]

       cut -c list [file ...]

       cut -f list [-s] [-d delim] [file ...]


 7120 cat error_json_2016-06-08.log|cut -d'\;' (실패)

 7127  cat error_json_2016-06-08.log|cut -d: -f1 (성공) -- -d랑 -f를 같이 써야되는군!



 7197  cat 1139_json.log|cut -d ';'    (실패)

 7198  cat 1139_json.log|cut -d '='    (실패)

 7199  cut 1139_json.log -d '='    (실패)

 7201  cat 1139_json.log |cut -d =    (실패)

 7202  cat 1139_json.log |cut -d=    (실패)

 7203  cat 1139_json.log |cut -f -d=     (실패)

 7203  cat 1139_json.log |cut -f1 -d=    (성공)

 7204  cat 1139_json.log |cut -cf -d=    (실패)

cut: [-cf] list: illegal list value


 7205  cat 1139_json.log |cut -cf    (실패)

 7207  cat 1139_json.log |cut -d '=' -f 2     (실패)



Posted by 썬,더 호글
,