![페이지를 매긴 출력을 위한 대화형 필터링 도구가 있습니까?](https://linux55.com/image/95574/%ED%8E%98%EC%9D%B4%EC%A7%80%EB%A5%BC%20%EB%A7%A4%EA%B8%B4%20%EC%B6%9C%EB%A0%A5%EC%9D%84%20%EC%9C%84%ED%95%9C%20%EB%8C%80%ED%99%94%ED%98%95%20%ED%95%84%ED%84%B0%EB%A7%81%20%EB%8F%84%EA%B5%AC%EA%B0%80%20%EC%9E%88%EC%8A%B5%EB%8B%88%EA%B9%8C%3F.png)
프로그램의 출력을 가져와 다음 명령으로 파이프되는 행을 대화식으로 필터링하고 싶습니다.
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
은 편집기(또는 편집기 실행 시도)가 실패할 때 출력 생성을 억제하는 것입니다.