pipe tail output into another script

前端 未结 3 1849
滥情空心
滥情空心 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:54

    Perhaps your were confused with awk?

    tail -n +1 -f your_log_file | awk '{
        print $1
    }'
    

    would print the first column from the output of the tail command.

    In the shell, a similar effect can be achieved with:

    tail -n +1 -f your_log_file | while read first junk; do
        echo "$first"
    done
    

    Alternatively, you could put the whole while ... done loop inside myscript.sh

提交回复
热议问题