问题
I'm using psql
to run a few commands, where the last one is something similar to: select max(id) from tablename
. I'm trying to get the id of the last row inserted. It returns the correct value (7)
in this scenario.
Begin Informatica Script SET INSERT 0 1 max ----- 7 (1 row) Redshift Delta copy completed at: 04/10/17 17:45:21 END
However, I'm trying to parse it and have no idea what to do... Is there a way to limit the output to just the value of 7
? If not, how do I grab just the number? There is the possibility of this becoming a rather large number as well, like 10,000
Edit: I added 2 options -qt
and got the output down to:
Begin Informatica Script 9 Redshift Delta copy completed at: 04/10/17 17:53:53 END
In that, 9
is the ID I want.
回答1:
With GNU sed:
echo 'Begin Informatica Script 9 Redshift Delta copy completed at: 04/10/17 17:53:53 END' | sed -r 's/.*Begin Informatica Script ([0-9,]+) Redshift Delta.*/\1/'
Output:
9
来源:https://stackoverflow.com/questions/43329771/is-there-a-correct-way-to-parse-output-in-bash-from-a-command