Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 895753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:36:37+00:00 2026-05-15T14:36:37+00:00

You can split a pipe using the tee command under linux as follows printf

  • 0

You can split a pipe using the tee command under linux as follows

printf "line1\nline2\nline3\n" | tee >(wc -l ) | (awk '{print "this is awk: "$0}')

which yields the output

this is awk: line1
this is awk: line2
this is awk: line3
this is awk: 3

My question, is that order of printing guaranteed? Will the tee split pipe that counts the number of lines always print at the end? Is there a way to always print it at the start? Or is the order of printing tee never guaranteed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:36:37+00:00Added an answer on May 15, 2026 at 2:36 pm

    It is not defined by tee, but as Daenyth says, wc won’t be finished until tee has finished passing it data – so usually tee will have passed it on to awk by then too. In this instance it might be better to have awk do the counting.

    echo -ne {one,two,three,four}\\n | \
    awk '{print "awk processing line " NR ": "$0} END {print "Awk saw " NR " lines"}'
    

    The downside being that it won’t know the number untils it finishes (knowing it requires buffering the data). In your example, both tee and wc have stdout connected to the same pipe (stdin for awk), but the order is undefined. cat (and most other piping tools) can be used to assemble files in a known order.

    There are more advanced piping techniques that could be used, such as bash coprocesses (coproc) or named pipes (mkfifo or mknod p). The latter gets you names in the filesystem, which can be passed to other processes, but you’ll have to clean them up and avoid collissions. tempfile or $$ may be useful for that. Pipes are not for buffering data, as they often have limited size and will simply block writes.

    An example of where pipes are the wrong solution:

    mkfifo wcin wcout
    wc -l < wcin > wcout &
    yes | dd count=1 bs=8M | tee wcin | cat -n wcout - | head
    

    The problem here is that tee will get stuck trying to write things to cat, which wants to finish with wcout first. There’s simply too much data for the pipe from tee to cat.

    Edit regarding dmckee’s answer:
    Yes, the order may be repeatable, but it is not guaranteed. It is a matter of scale, scheduling and buffer sizes. On this GNU/Linux box, the example starts breaking up after a few thousand lines:

    seq -f line%g 20000 | tee >(awk '{print "*" $0 "*"}' ) | \
    (awk '{print "this is awk: "$0}') | less
    this is awk: line2397
    this is awk: line2398
    this is awk: line2*line1*
    this is awk: *line2*
    this is awk: *line3*
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can split(string, array, separator) in awk use sequence of whitespaces as the separator (or
If I have a pipe separated list can I split them automatically into an
Expected Behavior Under normal circumstances, I can issue tshark -E separator='@' under linux See
I can split a string with a comma using preg_split , like $words =
I want to split each line of a pipe on spaces, and then print
I'd like to know how I can split a large file without using too
I would like to know how i can split this using jquery... {answer:[q1001-a2,q1002-a2,q1003-a2,q1004-a2,q1005-a2,q1006-a2]} So
Do MySQL have any function by which I can split data of a column
When I write: MyClass *obj = [[MyClass alloc]init]; I can split in 2 parts:
How can I split a String by Unicode range in Ruby. I wanted to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.