Reputation: 997
I use a bash script from an upstream repo that echos the high level progress as it goes through the script. At the end it displays a path/filename for the results of the script. I'm trying to get that path/file name without modifying the script since the script changes frequently. I can't figure out how to get the path/filename.
grep
then I lose the progress output text.awk
with a regex to match I also lose the progress output text.sed
, is failing and I don't know if it is the match, the command substitution, or the wrong tool for the job.I've spent a lot of time and thought now might be a good time to ask:
How should I do this?
Here's a sample just to demonstrate the output.
#!/bin/bash
echo "The directory to be analyzed abc123/def456/"
echo "## CPU"
echo "## Messages"
echo "## Out of Memory"
echo "Calling other script..."
echo "Done."
echo
echo "## Please check out the file /tmp/report_user1/def456-2020-12-02.log"
Output. I'm trying to grab the path/filename from the last line.
The directory to be analyzed abc123/def456/
## CPU
## Messages
## Out of Memory
Calling other script...
Done.
## Please check out the file /tmp/report_user1/def456-2020-12-02.log
Thank-you.
Upvotes: 1
Views: 47
Reputation: 1986
To view stdout on your terminal plus capture / filter, one method without tmp files is piping the output from any [utility or script] into tee /dev/tty
, along with piping the tee
output to a filter, eg:
util | tee /dev/tty | grep '\.log$'
capturing the above to a bash variable:
var=$(util | tee /dev/tty | grep '\.log$')
From the OP's description the above could be scripted, tee
output could reduced by other methods, log file copied, then exec $EDITOR ./copy.log
Upvotes: 1