Register
It is currently Mon Dec 22, 2014 1:42 pm

Output only the last line of a git command


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Fri Jul 23, 2010 2:41 am   

Joined: Fri Jul 23, 2010 2:23 am
Posts: 2
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!


Top
 Profile  
 PostPosted: Fri Jul 23, 2010 10:38 am   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
'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


Top
 Profile  
 PostPosted: Mon Jul 26, 2010 12:16 am   

Joined: Fri Jul 23, 2010 2:23 am
Posts: 2
Well,

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

Thanks.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP