잘라내기 명령 오류: 구분 기호는 단일 문자여야 합니다.

잘라내기 명령 오류: 구분 기호는 단일 문자여야 합니다.

bash-4.3에서 다음 명령을 시도하고 있습니다.

$history | grep history | xargs cut -d ' ' -f1

하지만 다음과 같은 구분 기호 오류가 발생하여 제거할 수 없습니다.

잘라내기: 구분 기호는 단일 문자여야 합니다.

xargs를 제거하려고 시도했지만 빈 출력이 나왔습니다. 전체 아이디어는기록에서 특정 명령 번호를 추출하여 삭제를 위해 기록 -d에 전달합니다.저것역사의 특정 명령. 이것은 단지 출력입니다

history | grep history



  498  history | grep history | cat | xargs cut -d " " -f1
  500  history | grep history | cat | xargs awk -ifs " "
  501  history | grep history | xargs cut -d " " -f1
  502  history | grep history | xargs cut -d '0' -f1
  503  history | grep history | xargs cut -d 0 -f1
  504* history | 
  505  history | ack history | xargs cut -d ' ' -f1
  506  history | ack history | xargs cut -d ' ' -f1
  507  history | ack history | cut -d ' ' -f1
  508  history | grep history 

답변1

몇 가지 설명:

  • 당신이 실제로 원하는 것은두번째필드이므로 `cut -d ' ' -f 2'로 변경해야 합니다.
  • xargs여기에는 적용되지 않습니다. 그것이 하는 일은 표준 입력을 받아 다음과 같이 전달하는 것입니다.논쟁주문에. 그러나 cut기본적으로 이는 사용자가 원하는 표준 입력에서 실행됩니다. history | grep history | xargs cut […]궁극적 으로 cut […] [some content from the Bash history]'.while read

    while IFS=$'\n' read -r -u9 number
    do
        history -d "$number"
    done 9< <(history | grep […] | cut […])
    
  • some_command | cat | other_command완전히 중복됩니다. cat기본적으로 표준 입력만 표준 출력에 복사됩니다.

답변2

이 명령을 시도해 보세요

    history | grep history | awk NR==1'{print $8 " " $9 " " $10 " " $11 " " $12 "" $13 }'
xargs cut -d ' '-f1

NR==1: awk테이블의 첫 번째 행에 있는 셀을 읽은 다음 "xargs cut -d ' '-f1"과 관련된 열(예: 8-12)을 인쇄합니다.

관련 정보