切り取りコマンドエラー:区切り文字は単一文字でなければなりません。

切り取りコマンドエラー:区切り文字は単一文字でなければなりません。

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デフォルトでは、標準入力のみが標準出力にコピーされます。

おすすめ記事