Output only the last line of a git command

Need a script ? Ask here.

Output only the last line of a git command

Postby mateju » Fri Jul 23, 2010 2:41 am

Hello,

I've made a simple script to commit files to git. There is a lot of output of commands git pull and git push. So, how do I output only the last line of the git command. I tried variations of git pull | tail -1 and grep, but can not figure it out.

I want git pull to only output the last line usually something like:
- X files changed, XXX insertions(+), XXX deletions(-)
- Already up-to-date.

or when using git push only
- 45604564 master -> master
...

I also wonder, how do I output only third line from last line? :)

M!
mateju
 
Posts: 2
Joined: Fri Jul 23, 2010 2:23 am

Re: Output only the last line of a git command

Postby Patsie » Fri Jul 23, 2010 10:38 am

'tail -1' should show you the last line of some output. Probably this last line is an empty line and you don't want to see that, but the last line with some actual text, right?. Then I suggest you first filter out all empty lines with a egrep -v "^$" and then do your tail -1.
If you want to see the 3rd last line, show the last 3 lines with a tail -3 and then show the first with head -1
User avatar
Patsie
 
Posts: 51
Joined: Sun Jun 27, 2010 12:57 am

Re: Output only the last line of a git command

Postby mateju » Mon Jul 26, 2010 12:16 am

Well,

This
$ git pull 2>&1 | tail -n1
gets the job done.

Thanks.
mateju
 
Posts: 2
Joined: Fri Jul 23, 2010 2:23 am


Return to Requests

Who is online

Users browsing this forum: No registered users and 1 guest