awk 명령줄 - 줄 제거

awk 명령줄 - 줄 제거

요청에 따라 게시 코드가 별도로 표시됩니다.

전류 출력

Name,Final Grade,Section
Andrew is an online student
Andrew,95,online
Brandon is an online student
Brandon,100,online
Chelsey is an onsite student
Chelsey,100,onsite
Deborah is an online student
Deborah,72,online
Erik is an online student
Erik,65,online
Arielle is an onsite student
Arielle,88,onsite
Shaun is an onsite student
Shaun,91,onsite
Ninette is an online student
Ninette,82,online
Nguyen is an onsite student
Nguyen,80,onsite

내가 달성해야 할 결과

Andrew is an online student
Brandon is an online student
Chelsey is an onsite student
Deborah is an online student
Erik is an online student
Arielle is an onsite student
Shaun is an onsite student
Ninette is an online student
Nguyen is an onsite student

기본적으로 입력 파일에서 행을 추가하고 헤더를 제거하지 않습니다. 내 문제는 그것을 제거하는 것입니다

  #!/usr/bin/awk -f
    ##comment create awk script that will output the given data in the format given in word document
    ##comment specify the delimiter as ","
    BEGIN { FS = "," }
    
    /./ {
    ##comment check if the third field is online, if print online
    if ($3 == "online")
    printf("%s is an online student\n", $1)
    
    ##commentcheck if the third field is onsite, if print onsite
    if ($3 == "onsite")
    printf("%s is an onsite student\n", $1)
    } $1

답변1

쉘 스크립트 내에서 $1스크립트가 호출되는 첫 번째 위치 매개변수(또는 인수)를 나타냅니다. 아마도 이를 사용하여 파일 이름을One-Shot Throwaway awk 프로그램

내부실행 가능한 awk 프로그램그러나 명령줄 인수는 awk 자체 ARGV배열을 통해 내부적으로 처리되며 $1현재 레코드의 첫 번째 필드입니다. 코드 블록 외부에서는 다음과 같습니다.

$1 != "" {
    print
}

따라서 FS문자가 아닌 문자가 하나 이상 포함된 모든 입력 줄을 출력합니다.

그러니 불필요한 것을 제거하세요 $1.

관련 정보