How to execute process output to the logger command and lead the command?

What I'm trying to do is:

  • Run a process that constantly displays text

  • The pipe, which is displayed on two teams:

    • Logger script
    • 'head', so I can save the first lines in the original process.

What I have tried so far (unsuccessfully):

./myProgram | tee > (myLogger log.txt) | head > firstLines.txt

The problem is that myProgram exits as soon as the head exits.

Even if I use the -i command in tee , I cannot get myProgram to continue to work.

Since the registrar can add incoming text to an existing file, executing head log.txt > firstLines.txt will not work in this case.

+6
source share
2 answers

You can use awk as an alternative for both:

 ./myProgram | awk 'NR<=10{print > "firstLines.txt"} NR>10{close("firstLines.txt")} 1' > log.txt 
+1
source

How is this possible:

 yes | awk 'FNR<4 {print >>"file"; close("file")} 1' | more 

where yes is your program, file is where you send the output to head to, and more is your registrar.

+1
source

All Articles