pipe tail output into another script

前端 未结 3 1846
滥情空心
滥情空心 2021-02-06 02:06

I am trying to pipe the output of a tail command into another bash script to process:

tail -n +1 -f your_log_file | myscript.sh

However, when I

3条回答
  •  南方客
    南方客 (楼主)
    2021-02-06 02:57

    Piping connects the output (stdout) of one process to the input (stdin) of another process. stdin is not the same thing as the arguments sent to a process when it starts.

    What you want to do is convert the lines in the output of your first process into arguments for the the second process. This is exactly what the xargs command is for.

    All you need to do is pipe an xargs in between the initial command and it will work:

    tail -n +1 -f your_log_file | xargs | myscript.sh

提交回复
热议问题