我正在构建一个shell脚本。
该脚本获取git日志,例如:
"Updating 2f8b547d..eb94967a Fast-forward...."
but I want to get 2f8b547d..eb94967a
snippet.
我是新手。因此,感谢您的帮助。
更新:
For the more, I want use the snippet as a param. Because I will excute
git log 2f8b547d..eb94967a
As an alternative to
awk
(don't get me wrong,awk
is super for this job as well), you can simply usecut
with aspace
delimiter extract the second field, e.g.You can also pipe output to
cut
or redirect the input file to it using<
as well. It essentially does the same as theawk
command, it just being a different choice of which utility to use.You can pipe it to
awk
like so:Your result will be
2f8b547d..eb94967a
.如果它是一个脚本(例如,abc.sh)具有这样的输出,则可以运行:
awk
takes the output and splits the information by space.Updating
is represented with $1.2f8b547d..eb94967a
is $2 and so on. In the above example, we askawk
to print out the 2nd item in the output.