프로그램의 출력을 가져와 다음 명령으로 파이프할 줄을 대화형으로 필터링하고 싶습니다.
ls | interactive-filter | xargs rm
예를 들어 패턴을 줄이기 위해 일치시킬 수 없는 파일 목록이 있습니다. interactive-filter
파일 목록의 출력을 페이징하고 다음 명령으로 전달할 행을 대화식으로 표시할 수 있는 명령을 원합니다 . 이 경우 각 줄은 제거됩니다.
답변1
iselect
사용자가 여러 항목에 태그를 지정할 수 있는(이전 파이프의 입력으로) 업다운 목록을 제공합니다(다음 파이프의 출력으로).# show some available executables ending in '*sh*' to run through `whatis` find /bin /sbin /usr/bin -maxdepth 1 -type f -executable -name '*sh' | iselect -t "select some executables to run 'whatis' on..." -a -m | xargs -d '\n' -r whatis
내 시스템에서 몇 가지 태그를 지정하기 위해 스페이스바를 누른 후의 출력:
dash (1) - command interpreter (shell) ssh (1) - OpenSSH SSH client (remote login program) mosh (1) - mobile shell with roaming and intelligent local echo yash (1) - a POSIX-compliant command line shell
vipe
파이프를 통과하는 내용을 대화식으로 편집(자신이 선호하는 텍스트 편집기 사용)할 수 있습니다. 예:# take a list of executables with long names from `/bin`, edit that # list as needed with `mcedit`, and run `wc` on the output. find /bin -type f | grep '...............' | EDITOR=mcedit vipe | xargs wc
출력(에서 일부 줄을 삭제한 후
mcedit
):378 2505 67608 /bin/ntfs-3g.secaudit 334 2250 105136 /bin/lowntfs-3g 67 952 27152 /bin/nc.traditional 126 877 47544 /bin/systemd-machine-id-setup 905 6584 247440 total
밀기 및 당기기에 대한 참고 사항:
iselect
다음과 같은 목록으로 시작합니다.아무것도 아님선택되었습니다.vipe
다음과 같은 목록으로 시작합니다.모든표시된 항목은 사용자가 삭제하지 않는 한 파이프를 통해 전송됩니다.
~ 안에데비안기반 배포판에서는 두 유틸리티 모두 apt-get install moreutils iselect
.
답변2
vipe
몇 줄의 쉘로 작성할 수 있습니다 . 나에게 맞는 빠르고 더러운 개념 증명:
EDITOR=vi # change to preferred editor as needed.
vipe()
{
cat > .temp.$$
if $EDITOR .temp.$$ < /dev/tty > /dev/tty 2>&1 ; then
cat .temp.$$
fi
rm .temp.$$
}
이것을 쉘에 소스화하면 거기에 있습니다. 의 목적은 if
편집기(또는 편집기 실행 시도)가 실패하는 경우 출력 생성을 억제하는 것입니다.