Replace names in git log using sed on MacOs (for Gource)

git log --grep regex
git replace
git grep in directory
git grep exclude binary
git grep show function name
git grep count
sed replace string with
git grep output

I'm trying to make a nice Gource video on our software develop project. Using Gource a can generate a combined git log of all repos with: first gource --output-custom-log ../logs/repo1.txt then cat *.txt | sort -n > combined.txt This generates a combined.txt file which is a pipe delimited file like:

1551272464|John|A|repo1/file1.txt
1551272464|john_doe|A|repo1/folder/file9.py
1551272464|Doe, John|A|repo2/filex.py

So its: EPOCH|Committer name|A or D or C|committed file

The actual problem I want to solve is the fact that my developers have used different git clients with different committer names so id like to replace all of their names to a single version. I do not mind setting multiple sed per situation. So find "John", "john_doe" and "Doe, John" and replace it with "John Doe". And it should be done on my MacBook.

So I tried sed -i -r "s/John/user_john/g" combined.txt but the problem here is that it finds "John" and "Doe, John" and replaces just the "John" part so I'm need to do a fuzzy search and replace the whole column.

Who can help me get the correct regex?

A regex would almost certainly be the wrong approach for this as you'd get false matches unless you were extremely careful and it's inefficient.

Just create an aliases file containing a line for each name you want in your output followed by all the names that should be mapped to it and then you can do this to change them all clearly, simply, robustly, portably, and efficiently in one call to awk:

$ cat tst.awk
BEGIN { FS="[|]" ; OFS="|" }
NR==FNR {
    for (i=2; i<=NF; i++) {
        alias[$i] = $1
    }
    next
}
$2 in alias { $2 = alias[$2] }
{ print }

.

$ cat aliases
John Doe|John|john_doe|Doe, John
Susan Barker|Susie B|Barker, Susan

.

$ cat file
1551272464|John|A|repo1/file1.txt
1551272464|Susie B|A|repo2/filex.py
1551272464|john_doe|A|repo1/folder/file9.py
1551272464|Doe, John|A|repo2/filex.py
1551272464|Barker, Susan|A|repo2/filex.py

.

$ awk -f tst.awk aliases file
1551272464|John Doe|A|repo1/file1.txt
1551272464|Susan Barker|A|repo2/filex.py
1551272464|John Doe|A|repo1/folder/file9.py
1551272464|John Doe|A|repo2/filex.py
1551272464|Susan Barker|A|repo2/filex.py

Highest Voted Questions - Page 155012, Replace names in git log using sed on MacOs (for Gource). I'm trying to make a nice Gource video on our software develop project. Using Gource a can� Unhappy with most other solutions provided (which is basically just a string-replace on git tracked files) I wrote my own script: git-sed. It supports any expression sed supports (e.g git sed '1{/^$/d}') Can run on a subset of paths in the repo (git sed 's/foo/bar' src tests) Multiple expressions (git sed -e 's/foo/bar' -e '/bar/d'). etc

As @WiktorStribizew mentioned, you can do:

sed -i -r "s/Doe, John|john_doe|John/user_john/g" combined.txt

And with that, you can even do:

sed -i -r -e "s/Doe, John|john_doe|John/user_john/g" -e "s/Wayne, Bruce|bruce_wayne|Bruce/user_bruce/g" combined.txt

And add more replacements to chain with the -e option:

   -e script, --expression=script
          add the script to the commands to be executed

Newest 'bash macos sed' Questions, Replace names in git log using sed on MacOs (for Gource) � regex bash git macos sed � Apr 16 '19 at 6:17 Emile Claassens. 0. 2� MacOS is different, there is two way to solve this problem with sed in mac. first ,use \'$' '' replace , it can work in MacOS: sed 's/,/\'$' ''/g' file the second, just use an empty line: sed 's/,/\ /g' file Ps. Pay attention the range separated by ' the third, use gnu-sed replace the mac-sed

try gnu sed:

sed -E "s/^(\w+\|)(john([\s_]doe)?|doe,\s*john)/\1John Doe/i" combined.txt

add -i option after examining to edit it; sed -Ei...

regex, 我正在尝试在我们的软件开发项目中制作一个不错的Gource视频。 使用Gource a 可以生成具有以下 Replace names in git log using sed on MacOs (for Gource). git log v2.6.12.. include/scsi drivers/scsi. Show all commits since version v2.6.12 that changed any file in the include/scsi or drivers/scsi subdirectories. git log --since="2 weeks ago" -- gitk. Show the changes during the last two weeks to the file gitk. The --is necessary to avoid confusion with the branch named gitk. git log --name-status

Use Git Grep to Replace Strings in Files in Your Git Repository , Use Git Grep to Replace Strings in Files in Your Git Repository. git grep -l ' original_text' | xargs sed -i 's/original_text/new_text/g' The -l argument to git grep only returns the file names and not the location in the file like it usually does. The -e argument is needed with the sed portion on OSX as stated by� Using sed to replace the hexadecimal code for URL and to insert new SVG codes after SVG tag in all SVG files 0 Complex string replace - multiple files, multiple different strings, must include certain text

regex - jQuery, Regex doesn't capture dynamic groups � Replace names in git log using sed on MacOs (for Gource) � How does `[][]` match “either [ or ]”? Perl Replace Simplify. If you use the -i option you need to provide an extension for your backups.. If you have: File1.txt File2.cfg The command (note the lack of space between -i and '' and the -e to make it work on new versions of Mac and on GNU):

[PDF] tldr pdf, git cherry-pick . Show only the file name from a path, with a suffix removed: repository, suitable for use as a remote over ssh: git init --bare git log. Show a history of commits. Run gource in the current directory, with a custom output resolution: sed. Run replacements based on regular expressions. – Replace the first� Setup Mac OS X. I've done the same process every couple years since 2013 (Mountain Lion, Mavericks, High Sierra, Catalina) and I updated the Gist each time I've done it. I kinda regret for not using something like Boxen (or anything similar) to automate the process, but TBH I only actually needed to these steps once every couple years

Comments
  • take the string between the first and the second "|"
  • sed -i -r "s/Doe, John|john_doe|John/user_john/g" combined.txt might do.
  • This is a far more elegant solution! I integrated it in my bash script and works like a charm. Really fast as wel.