I have the example text stored in test.sh
:
echo 'Hello world 123'
echo 'some other text'
With the following command in a bash script:
word123=$(./test.sh |sed -nr 's/Hello world (.*)/\\1/p' )
This works correctly and outputs:
123
However, this does output
Hello world 123
some other text
Is there a way to capture the text in 123
and also output everything else in the file?
With Linux , bash
and tee
:
word123=$( ./test.sh | tee >&255 >(sed -nr 's/Hello world (.*)/\1/p') )
File descriptor 255 is a non-redirected copy of stdout.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.