안녕하세요
table 에 proto_header라는 컬럼이 있고 해당 칼럼을 조회 했을때 아래와 같은 다중 행이 띁다고 가정할때 특정 키워드만 조회할 수 있는 방안에 대해서 자문을 구하고 싶습니다.
예를들어 아래와 같은 CSV파일이 있습니다.
1.1.1.1,80,"GET /arm/win/xxxx2.msi HTTP/1.1
Connection: Keep-Alive
Accept: */*
Accept-Encoding: identity
If-Unmodified-Since: Tue, 16 May 2017 12:27:02 GMT
Range: bytes=0-4913
User-Agent: Microsoft BITS/7.5
Host: xxx.xxxx.com
HTTP/1.1 206 Partial Content
Server: Apache
Last-Modified: Tue, 16 May 2017 12:27:02 GMT
ETag: ""4600-54fa349f7d4bb""
Accept-Ranges: bytes
Content-Type: application/x-msi
Date: Sun, 09 Jul 2017 21:45:34 GMT
Content-Range: bytes 0-4913/17920
Content-Length: 4914
Connection: keep-alive"
해당 내용은 아래의 URL에 접속했을 때 TCP stream이라고 할 때
저는 불필요한 정보 없이 아래와 같은 데이터의 중복값을 제외하고 추출하고 싶습니다.
1.1.1.1:80/arm/win/xxxx2.msi
xxx.xxxx.com/arm/win/xxxx2.msi
하지만 해당내용을 DB화 하면 아래와 같이 결과가 나옵니다.
dst_ip | 1.1.1.1
dst_port | 80
proto_header | GET /arm/win/xxxx2.msi HTTP/1.1\r
| Connection: Keep-Alive\r
| Accept: */*\r
| Accept-Encoding: identity\r
| If-Unmodified-Since: Tue, 16 May 2017 12:27:02 GMT\r
| Range: bytes=0-5369\r
| User-Agent: Microsoft BITS/7.5\r
| Host: xxx.xxxx.com\r
| \r
| HTTP/1.1 206 Partial Content\r
| Server: Apache\r
| Last-Modified: Tue, 16 May 2017 12:27:02 GMT\r
| ETag: "4600-54fa349f7d4bb"\r
| Accept-Ranges: bytes\r
| Content-Type: application/x-msi\r
| Date: Mon, 10 Jul 2017 01:19:19 GMT\r
| Content-Range: bytes 0-5369/17920\r
| Content-Length: 5370\r
| Connection: keep-alive\r
| \r
맨 윗줄만 표기하게 해서
dst_ip | dst_port | proto_header |
Comment 3
-
건우아빠
2017.07.13 16:49
-
궁금해서알고싶어요
2017.07.14 15:47
제가 설명을 이상하게 해서.. 다시 상세하게 작성하였습니다.
-
건우아빠
2017.07.14 18:02
중복가 제거라기 보다는 필요한 값만 추출하는 거같습니다.
테이블 구성이 proto_header 컬럼에 값이 다들어간 다는것인지 .
한줄씩 들어가는지가 ?
proto_header 컬럼 값에서 GET , si 의 위치 값을 가지고 추출 하시면 될것 같습니다.
postgresql 문자열 위치값 추출 mssql과 같은것 같네요
-- substring(proto_header ,2, 4)
문자열 찾기 (mssql -charindex)
-- strpos(proto_header ,'GET') , strpos(proto_header ,'si')
-- 시작 위치이므로 글자수 만큼 더한 값을 시작으로 두값으 차이 만큼 가져오시면 되지 않을까요
참고로 구글이나 naver에서 검색하실때
postgresql mssql charindx
postgresql mssql substring
이런식으로 검색하시면 원하는 내용을 손쉽게 찾으실수 있습니다.