Is there any way to read lines from command output?

Marcus Thornton

I have a pre process command to output a file

./preprocess.sh > preprocessed_file 

and the preprocessed_file will be used like this

while read line
do

    ./research.sh $line &

done < preprocessed_file 

rm -f preprocessed_file

Is there any way to direct the output to the while read line part instead of outputting to the preprocessed_file? I think there should be a better way other than using this temp preprocessed_file.

cuonglm

You can use bash process substitution:

while IFS= read -r line; do
  ./research.sh "$line" &
done < <(./preprocess.sh)

Some advantages of process substitution:

  • No need to save temporary files.
  • Better performance. Reading from another process often faster than writing to disk, then read back in.
  • Save time to computation since when it is performed simultaneously with parameter and variable expansion, command substitution, and arithmetic expansion

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Read specific floating point values from lines of the command output

From Dev

Is there a way to find out the number of lines from a command output?

From Dev

Is there any way to suppres the output of plot() command in Scilab

From Dev

Is there any way to have VoiceOver read a label on command?

From Dev

Read any number of lines from standard input

From Dev

bash - count and output lines from command

From Dev

Linux cat command output with new lines to be read using vim

From Dev

how to read certain lines of a file that is the output of fc command with a batch script

From Dev

python read from shell command output

From Dev

Shell Scripting: read input from command output

From Dev

Is there is any way to Read mapdb map from hdfs?

From Dev

Any way to change the tab size of the diff command's output?

From Dev

Is there any way to make the cut command read the last field only?

From Dev

Is there any way to make the cut command read the last field only?

From Dev

Unexpected output from textfile - cleaning read in lines correctly

From Dev

Read lines from a file and output each line with a line number

From Dev

Read lines from a file and output each line with a line number

From Dev

Check for zero lines output from command over SSH

From Dev

How to create an array from the lines of a command's output

From Dev

How to create an array from the lines of a command's output

From Dev

How to insert tabs before output lines from a executed command

From Dev

Capture output from command into variable retaining new lines

From Dev

grep lines starting with - or plus from yum command output

From Dev

Read lines from a file into command window and expand variables

From Dev

How to read input lines with newline characters from command line?

From Dev

Simple way to read variables on different lines from STDIN?

From Dev

Is this the right way to read lines from file and split them into words in Rust?

From Dev

Best way to read lines from file Java 8 and break in between

From Dev

Easiest way to read multiple lines (as a sliding window) from a file

Related Related

  1. 1

    Read specific floating point values from lines of the command output

  2. 2

    Is there a way to find out the number of lines from a command output?

  3. 3

    Is there any way to suppres the output of plot() command in Scilab

  4. 4

    Is there any way to have VoiceOver read a label on command?

  5. 5

    Read any number of lines from standard input

  6. 6

    bash - count and output lines from command

  7. 7

    Linux cat command output with new lines to be read using vim

  8. 8

    how to read certain lines of a file that is the output of fc command with a batch script

  9. 9

    python read from shell command output

  10. 10

    Shell Scripting: read input from command output

  11. 11

    Is there is any way to Read mapdb map from hdfs?

  12. 12

    Any way to change the tab size of the diff command's output?

  13. 13

    Is there any way to make the cut command read the last field only?

  14. 14

    Is there any way to make the cut command read the last field only?

  15. 15

    Unexpected output from textfile - cleaning read in lines correctly

  16. 16

    Read lines from a file and output each line with a line number

  17. 17

    Read lines from a file and output each line with a line number

  18. 18

    Check for zero lines output from command over SSH

  19. 19

    How to create an array from the lines of a command's output

  20. 20

    How to create an array from the lines of a command's output

  21. 21

    How to insert tabs before output lines from a executed command

  22. 22

    Capture output from command into variable retaining new lines

  23. 23

    grep lines starting with - or plus from yum command output

  24. 24

    Read lines from a file into command window and expand variables

  25. 25

    How to read input lines with newline characters from command line?

  26. 26

    Simple way to read variables on different lines from STDIN?

  27. 27

    Is this the right way to read lines from file and split them into words in Rust?

  28. 28

    Best way to read lines from file Java 8 and break in between

  29. 29

    Easiest way to read multiple lines (as a sliding window) from a file

HotTag

Archive