How do I extract the names from the gitolite info command output, for further piping into a script?I'm writing a migration script to migrate all my repositories from gitolite to a Gitlab server. Thus, I want to get all the repository names from gitolite and use those in Gitlab. Below is the example output I'm trying to match against.hello sitaram, this is gitolite v2.1-29-g5a125fa running on git 1.7.4.4the gitolite config gives you the following access:     R      SecureBrowse     R   W  anu-wsd     R   W  entrans    @R   W  git-notes    @R   W  gitolite     R   W  gitolite-admin     R   W  indic_web_input @C  R   W  private/sitaram/[\w.-]+     R   W  proxy @C @R   W  public/sitaram/[\w.-]+    @R_ @W_ testing     R   W  vicThis should output:SecureBrowseanu-wsdentransgit-notesgitolitegitolite-adminindic_web_inputproxytestingvkcCurrently I'm trying to put this in a shell script, so it would be usable for others. My current approach is a grep command, which looks like the following:grep -Eio ([A-Za-z0-9_-]+)$ gitolite-info-outputHowever, this also captures the 4 at the end of the first line. I've been trying several approaches, but I can't seem to exclude that properly, without including or excluding other things.Doing this OS X 10.10.3.
Find repository names from gitolite info output
shell script;text processing;grep;regular expression;git
Based on the input you show in your question, this should work:$ grep -oP '^[ @]*R.* \K.*' gitolite-info-outputSecureBrowseanu-wsdentransgit-notesgitolitegitolite-adminindic_web_inputproxytestingvicThis is using GNU grep's -P switch to enable Perl Compatible Regular Expressions which give us \K : Exclude anything matched up to this point. Combined with -o, we can search for lines starting with 0 or more spaces or @ (^[ @]*), then an R, then 0 or more characters until another space. All this is discarded because of the \K so only the last word is printed.If you don't have GNU grep (on OSX, for example), you can do something like this:$ grep -E '^[ @]*R' gitolite-info-output | awk '{print $NF}'SecureBrowseanu-wsdentransgit-notesgitolitegitolite-adminindic_web_inputproxytestingvicOr do the whole thing in awk:$ awk '/^[ @]*R/{print $NF}' gitolite-info-output SecureBrowseanu-wsdentransgit-notesgitolitegitolite-adminindic_web_inputproxytestingvicOr Perl:$ perl -nle '/^[ @]*R.*\s(.*)/ && print $1' gitolite-info-output SecureBrowseanu-wsdentransgit-notesgitolitegitolite-adminindic_web_inputproxytestingvic