Skip to main content
added 1169 characters in body
Source Link
Chris
  • 1.1k
  • 1
  • 13
  • 25

For example, suppose I define a variable:

DROP=

And I have a loop:

# highly compatible, streaming, 
# line-wise parser for embedded device
# no awk or external dependency
while IFS= read -r line; do 

  ...
  generate_output_1 | xargs echo
  ...
  generate_output_2 | xargs echo
  ...
  generate_output_N | xargs echo 

done <<<$(cleanFile x.txt) > "$OUTPUT_STREAM"

How would I toggle the ability to forward the output? I can think of defining a function, but is there a command that allows the output to be turned off or on?

# e.g. 
DROP=-d
generate_output | spigot ${DROP}

To address the comments, before asking this question, I used if statements. For those of you familiar with a streaming parser, avoiding if statements where possible is fundamentally important, since you tend to require if-statements in the body of the while loop already. So I'll go to some length to avoid any of the if statement solutions, including any control expressions (e.g. [ .. ] && ... || ...).

Secondly, I tried defining a PIPE variable:

if [ -z "$DROP" ]; then 
  PIPE=/dev/stdout
else
  PIPE=/dev/null
fi

And appended it in place of ... | xargs echo. This should have worked, intuitively. In practical terms, it did not work inside my while loop in my version of BASH and virtualization environment. That is because I've already used that technique in managing the output of my while loop. The final line of the example is making use of the technique already. In the OUTPUT_STREAM, I swap around files based on arguments or default to /dev/stdout:

done <<<$(cleanFile x.txt) > "$OUTPUT_STREAM"

What I am really looking for is a concise command that does what spigot does. And that is all.

For example, suppose I define a variable:

DROP=

And I have a loop:

# highly compatible, streaming, 
# line-wise parser for embedded device
# no awk or external dependency
while IFS= read -r line; do 

  ...
  generate_output_1 | xargs echo
  ...
  generate_output_2 | xargs echo
  ...
  generate_output_N | xargs echo 

done <<<$(cleanFile x.txt) > "$OUTPUT_STREAM"

How would I toggle the ability to forward the output? I can think of defining a function, but is there a command that allows the output to be turned off or on?

# e.g. 
DROP=-d
generate_output | spigot ${DROP}

For example, suppose I define a variable:

DROP=

And I have a loop:

# highly compatible, streaming, 
# line-wise parser for embedded device
# no awk or external dependency
while IFS= read -r line; do 

  ...
  generate_output_1 | xargs echo
  ...
  generate_output_2 | xargs echo
  ...
  generate_output_N | xargs echo 

done <<<$(cleanFile x.txt) > "$OUTPUT_STREAM"

How would I toggle the ability to forward the output? I can think of defining a function, but is there a command that allows the output to be turned off or on?

# e.g. 
DROP=-d
generate_output | spigot ${DROP}

To address the comments, before asking this question, I used if statements. For those of you familiar with a streaming parser, avoiding if statements where possible is fundamentally important, since you tend to require if-statements in the body of the while loop already. So I'll go to some length to avoid any of the if statement solutions, including any control expressions (e.g. [ .. ] && ... || ...).

Secondly, I tried defining a PIPE variable:

if [ -z "$DROP" ]; then 
  PIPE=/dev/stdout
else
  PIPE=/dev/null
fi

And appended it in place of ... | xargs echo. This should have worked, intuitively. In practical terms, it did not work inside my while loop in my version of BASH and virtualization environment. That is because I've already used that technique in managing the output of my while loop. The final line of the example is making use of the technique already. In the OUTPUT_STREAM, I swap around files based on arguments or default to /dev/stdout:

done <<<$(cleanFile x.txt) > "$OUTPUT_STREAM"

What I am really looking for is a concise command that does what spigot does. And that is all.

Source Link
Chris
  • 1.1k
  • 1
  • 13
  • 25

Is there a native linux command other than awk/sed/perl/python that can toggle pipe output on or off?

For example, suppose I define a variable:

DROP=

And I have a loop:

# highly compatible, streaming, 
# line-wise parser for embedded device
# no awk or external dependency
while IFS= read -r line; do 

  ...
  generate_output_1 | xargs echo
  ...
  generate_output_2 | xargs echo
  ...
  generate_output_N | xargs echo 

done <<<$(cleanFile x.txt) > "$OUTPUT_STREAM"

How would I toggle the ability to forward the output? I can think of defining a function, but is there a command that allows the output to be turned off or on?

# e.g. 
DROP=-d
generate_output | spigot ${DROP}