Skip to content

Instantly share code, notes, and snippets.

@evilchili
Created September 2, 2011 19:17
Show Gist options
  • Save evilchili/1189569 to your computer and use it in GitHub Desktop.
Save evilchili/1189569 to your computer and use it in GitHub Desktop.
replace mixed-case usernames in a JIRA export file with their lowercase equivalents
#!/bin/bash
#
# grep "Membership.*jira-users" entities.xml
# -- extract the lines of XML defining members of jira-users. for JIRA 4.4, these lines look like:
# <Membership id="10002" parentId="10002" childId="10000" membershipType="GROUP_USER" parentName="jira-users" lowerParentName="jira-users" childName="Greg.Boyington" lowerChildName="greg.boyington" directoryId="1"/>
#
# cut -d' ' -f12
# -- extract just the childName attribute eg. childName="Greg.Boyington"
#
# awk '{FS="\""; print $2}'
# -- extract the usernames only eg. Greg.Boyington
#
# sort -fr
# -- sort the Mixed.Case and lower.case usernames alphabetically, Mixed.Case first
#
# uniq -i
# -- select only the Mixed.Case usernames
#
# sed -i "s/$u/\L$u/g" entities.xml
# -- replace all occurrences of $u, the Mixed.Case username, with the lowercase equivalent
cp entities.xml entities.xml.orig
for u in `grep "Membership.*jira-users" entities.xml.orig| cut -d' ' -f12|awk '{FS="\""; print $2}'|sort -fr|uniq -i`; do sed -i "s/$u/\L$u/g" entities.xml; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment