내용이 다음과 같은 파일이 있습니다.
ae-scc-san-vserver01 /vol/ae_drac02_1_oradminvg_vol/ae_drac02_1_oradminvg_lun hdisk0 fcs0 FCP 150g C
ae-scc-san-vserver01 /vol/ae_drac02_1_rootvg_vol/ae_drac02_1_rootvg_lun hdisk1 fcs0 FCP 100g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskcrs03SVC_vol/ae_drac02_1_2_hdiskcrs03SVC_lun hdisk11 fcs0 FCP 16.0g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskdata01SVC_vol/ae_drac02_1_2_hdiskdata01SVC_lun hdisk12 fcs0 FCP 240.0g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskdata02SVC_vol/ae_drac02_1_2_hdiskdata02SVC_lun hdisk13 fcs0 FCP 240.0g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskdata03SVC_vol/ae_drac02_1_2_hdiskdata03SVC_lun hdisk14 fcs0 FCP 240.0g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskdata04SVC_vol/ae_drac02_1_2_hdiskdata04SVC_lun hdisk15 fcs0 FCP 240.0g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskdata05SVC_vol/ae_drac02_1_2_hdiskdata05SVC_lun hdisk17 fcs0 FCP 240.0g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskdata06SVC_vol/ae_drac02_1_2_hdiskdata06SVC_lun hdisk18 fcs0 FCP 240.0g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskdata12SVC_vol/ae_drac02_1_2_hdiskdata12SVC_lun hdisk19 fcs0 FCP 250g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskdata13SVC_vol/ae_drac02_1_2_hdiskdata13SVC_lun hdisk20 fcs0 FCP 250g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskdata14SVC_vol/ae_drac02_1_2_hdiskdata14SVC_lun hdisk21 fcs0 FCP 250g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskdata15SVC_vol/ae_drac02_1_2_hdiskdata15SVC_lun hdisk22 fcs0 FCP 250g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskdata16SVC_vol/ae_drac02_1_2_hdiskdata16SVC_lun hdisk23 fcs0 FCP 250g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskdata17SVC_vol/ae_drac02_1_2_hdiskdata17SVC_lun hdisk24 fcs0 FCP 250g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskdata18SVC_vol/ae_drac02_1_2_hdiskdata18SVC_lun hdisk25 fcs0 FCP 250g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskdata19SVC_vol/ae_drac02_1_2_hdiskdata19SVC_lun hdisk26 fcs0 FCP 250g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskdata20SVC_vol/ae_drac02_1_2_hdiskdata20SVC_lun hdisk27 fcs0 FCP 250g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskdata21SVC_vol/ae_drac02_1_2_hdiskdata21SVC_lun hdisk28 fcs0 FCP 250g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskdata22SVC_vol/ae_drac02_1_2_hdiskdata22SVC_lun hdisk29 fcs0 FCP 250g C
ae-scc-san-vserver01 /vol/ae_drac02_1_swapvg_vol/ae_drac02_1_swapvg_lun hdisk3 fcs0 FCP 32.0g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskdata23SVC_vol/ae_drac02_1_2_hdiskdata23SVC_lun hdisk30 fcs0 FCP 250g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskfra01SVC_vol/ae_drac02_1_2_hdiskfra01SVC_lun hdisk31 fcs0 FCP 240.0g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskfra02SVC_vol/ae_drac02_1_2_hdiskfra02SVC_lun hdisk32 fcs0 FCP 240.0g C
ae-scc-san-vserver01 /vol/ae_drac02_1_u01vg_vol/ae_drac02_1_u01vg_lun hdisk4 fcs0 FCP 170.0g C
ae-scc-san-vserver01 /vol/ae_drac02_1_exportsvg_vol/ae_drac02_1_exportsvg_lun hdisk5 fcs0 FCP 100g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskcrs01SVC_vol/ae_drac02_1_2_hdiskcrs01SVC_lun hdisk6 fcs0 FCP 16.0g C
ae-scc-san-vserver01 /vol/ae_drac02_1_2_hdiskcrs02SVC_vol/ae_drac02_1_2_hdiskcrs02SVC_lun hdisk7 fcs0 FCP 16.0g C
서버 이름을 캡처해야 합니다. 로 시작 hdisk
하고 로 끝납니다 SVC
. 나는 다음을 시도했다:
sed 's/^*hdisk(.*)SVC.*/\1/' filename
다음 오류가 발생합니다.
sed: 1: "s/^*hdisk(.*)SVC.*/\1/": \1 not defined in the RE
누군가 그것을 캡처하는 방법을 도와줄 수 있습니까?
답변1
문제가 hdisk...SVC
발생합니다두 배행에 .*
있고 ,탐욕스러운.
GNU grep이 있는 경우 이 -P
옵션을 사용하여 탐욕스럽지 않은 일치 항목을 얻을 수 있습니다.
grep -oP '(?<=hdisk).+?(?=SVC)' file | sort -u
산출
crs01
crs02
crs03
data01
data02
data03
data04
data05
data06
data12
data13
data14
data15
data16
data17
data18
data19
data20
data21
data22
data23
fra01
fra02
답변2
대괄호를 이스케이프 처리해야 합니다. 또한 hdisk와 SVC 사이의 여러 문자를 일치시키려면 별표나 다른 방법을 사용해야 합니다. 예를 들어:
sed 's/^hdisk\([^\/]*\)SVC.*/\1/' filename
답변3
awk
- 기반 방법을 사용할 수도 있습니다 .
GNU Awk 사용:
awk 'match($2,/^\/vol[[:print:]]*hdisk([^_]+)SVC/,v) {print(v[1])}' filename
두 번째 열에 패턴이 포함된 모든 행과 일치하고 /vol<...>hdisk<...>SVC<...>
그 사이의 문자열을 인쇄합니다.hdisk
첫 번째 SVC
, 밑줄이 _
제외되었기 때문입니다.
다른 방법(휴대 가능해야 함)
awk 'split($2,v,/hdisk|SVC/)>1 {print v[2];next}' filename
및 필드 구분 기호를 사용하여 두 번째 열을 여러 필드로 분할 hdisk
하고 SVC
여러 필드가 발견되면 두 번째 필드를 인쇄합니다.