awk가 필요한 출력을 생성하지 않습니다.

awk가 필요한 출력을 생성하지 않습니다.

아래는 내 명령 출력입니다. 을 통해 처리하면 awk원하지 않는 출력이 발생합니다. 내가 뭘 잘못했나요?

# lvdisplay -m
  --- Logical volume ---
  LV Name                /dev/Appsvg/apps01
  VG Name                Appsvg
  LV UUID                TckScf-LXdY-BvU1-NGhQ-5vUQ-KoNz-Uus1Of
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                15.00 GB
  Current LE             3840
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

  --- Segments ---
  Logical extent 0 to 3839:
    Type                linear
    Physical volume     /dev/emcpoweraq
    Physical extents    0 to 3839


  --- Logical volume ---
  LV Name                /dev/Appsvg/apps02
  VG Name                Appsvg
  LV UUID                FcMopR-57MH-aTrT-3bq2-wUJZ-blEI-161Ivz
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                10.00 GB
  Current LE             2560
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

  --- Segments ---
  Logical extent 0 to 2559:
    Type                linear
    Physical volume     /dev/emcpoweraq
    Physical extents    3840 to 6399


  --- Logical volume ---
  LV Name                /dev/Appsvg/apps03
  VG Name                Appsvg
  LV UUID                Ji4ldh-2ffZ-9qmb-BVaz-rwYd-f9HQ-2imPYG
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                20.00 GB
  Current LE             5120
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2

  --- Segments ---
  Logical extent 0 to 5119:
    Type                linear
    Physical volume     /dev/emcpoweraq
    Physical extents    6400 to 11519
# lvdisplay -m|awk '/(LV Name)/{l=$3} /(Physical volume)/{p=$3} {print l,p;}'

/dev/Appsvg/apps01
/dev/Appsvg/apps01
/dev/Appsvg/apps01
/dev/Appsvg/apps01
/dev/Appsvg/apps01
/dev/Appsvg/apps01
/dev/Appsvg/apps01
/dev/Appsvg/apps01
/dev/Appsvg/apps01
/dev/Appsvg/apps01
/dev/Appsvg/apps01
/dev/Appsvg/apps01
/dev/Appsvg/apps01
/dev/Appsvg/apps01
/dev/Appsvg/apps01
/dev/Appsvg/apps01
/dev/Appsvg/apps01
/dev/Appsvg/apps01 /dev/emcpoweraq
/dev/Appsvg/apps01 /dev/emcpoweraq
/dev/Appsvg/apps01 /dev/emcpoweraq
/dev/Appsvg/apps01 /dev/emcpoweraq
/dev/Appsvg/apps01 /dev/emcpoweraq
/dev/Appsvg/apps02 /dev/emcpoweraq
/dev/Appsvg/apps02 /dev/emcpoweraq
/dev/Appsvg/apps02 /dev/emcpoweraq
/dev/Appsvg/apps02 /dev/emcpoweraq
/dev/Appsvg/apps02 /dev/emcpoweraq
................. output snipped.......

"LV 이름"과 "물리적 볼륨"만 보일 것으로 예상했습니다. 이는 항목이 한 번만 표시될 수 있음을 의미합니다. 내 예상 결과는 다음과 같습니다.

/dev/Appsvg/apps01 /dev/emcpoweraq
/dev/Appsvg/apps02 /dev/emcpoweraq
/dev/Appsvg/apps03 /dev/emcpoweraq

답변1

p=$3내 추측이 맞다면 마지막 두 문( 및 print l,p) 을 결합하려면 추가 중괄호 세트가 필요합니다 .

                                                           /-     HERE    -\
                                                          \/               \/
lvdisplay -m | awk '/(LV Name)/{l=$3} /(Physical volume)/{{p=$3} {print l,p;}}'

Ulrich Schwarz의 의견과 관련하여 더 분명할 수 있습니다.

lvdisplay -m | awk '/(LV Name)/{l=$3} /(Physical volume)/{p=$3; print l,p;}'

질문의 명령은 awk예상대로 "l"과 "p"를 할당하지만 "print l,p" 앞에는 조건이 없으므로 모든 줄에서 실행됩니다.

관련 정보