IT/Unix&Linux
cat 으로 읽은 여러줄 멀티라인 xargs 로 각각 넘기기
iezs
2018. 11. 20. 22:25
우선..
cat 으로 멀티라인을 읽어서 xargs 로 처리하고 싶은데 멀티라인이 아니라 하나만 처리될경우.... (사실 전체가 하나로 넘어가는거겠지만)
이때 하나하나 라인마다 실행하고 싶으면
from https://unix.stackexchange.com/questions/7558/execute-a-command-once-per-line-of-piped-input
The accepted answer has the right idea, but the key is to pass xargs
the -n1
switch, which means "Execute the command once per line of output:"
cat file... | xargs -n1 command
Or, for a single input file you can avoid the pipe from cat
entirely and just go with:
<file xargs -n1 command
answered Nov 18 '14 at 15:44
와!! 그래 -n1 이다 .. 아주 좋은 명령이네;
xargs
to not run ifstdin
is empty:--no-run-if-empty
-r
: If the standard input does not contain any nonblanks, do not run the command. Normally, the command is run once even if there is no input. This option is a GNU extension. – Ronan Jouchet Oct 24 '15 at 19:58command
? – B T Apr 14 '16 at 1:21