I'm trying to parse the output of commands run in a bash loop. Here is an example:$ for i in `git log --format='%H'`; do echo $i ; git branch --contains $i; done | head -n 85f11ce7da2f9a4c4899dc2e47b02c2d936d0468e* foobare1c3f6fabd45715b527a083bc797e9723c57ac89  dev1* foobar7053e08775d2c1da7480a988a235e445799cbca5  dev1* foobarThe command git log --format='%H' prints out only the commit ID for each Git commit. The command git branch --contains $i prints out which Git branches contain the commit.I'm trying to find the latest git commit that is not on branch 'foobar'. I would like to echo $i for the first branch whose output of git branch --contains $i contains a line that does not start with the * character, which specifies current branch. What Bash documentation should I be reading?Note that I am aware of other solutions to this problem. However, I plan on making additions that the other answers do not account for. Furthermore, this is how I improve my Bash scripting abilities.
Parse lines of output from bash loop
bash;shell script;text processing;git
Something like this might be what you want.for i in $(git log --format='%H'); do    branch=$(git branch --contains $i|awk 'NR==1{print $1}')    [ $branch != * ] && echo commit '$i' is in branch '$branch'donePrints the commit and its branch if not the current branch.