I am trying to stdin only lines from 1 to 1000 from a file (output.txt) to a while loop.
I have tried something like this:
#!/bin/bash
while read -r line; do
echo "$line"
done < (sed -n 1,1000p data/output.txt)
Just tried:
#!/bin/bash
while read -r line; do
echo "$line"
done < <(sed -n 1,1000p data/output.txt)
adding another angular bracket "<" did the trick... If someone can explain that could be interesting.
Thanks
the part <(
)
, is called process substitution, it can replace a filename in a command.
fifos can also be used to do the same thing.
mkfifo myfifo
sed -n 1,1000p data/output.txt > myfifo &
while read -r line; do
echo "$line"
done < myfifo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With