This script updates usernames in a Mattermost JSONL import file to match existing users in a Mattermost instance. It's particularly useful when migrating from Slack to Mattermost and you need to ensure usernames in the import file match those of existing Mattermost users.
- Bash environment (macOS or Linux)
mmctl
installed and configured with access to your Mattermost instance- The JSONL import file from Slack export
- Updates usernames in user records based on email matching
- Updates usernames in post records
- Updates @mentions in message content
- Preserves the original file and creates a new one with updates
- Provides detailed status for each processed user
- Shows a summary of all modifications
./update_users.sh <input_file> <output_file>
Example:
./update_users.sh mattermost_import.jsonl updated_import.jsonl
The script provides real-time feedback with color-coded status:
- 🟡
[MODIFIED]
: Username was updated - 🟢
[UNCHANGED]
: Username already matches - 🔵
[NOT FOUND]
: User doesn't exist in Mattermost
At the end, it displays a summary with:
- Total number of user records processed
- Number of modified records
- Number of unchanged records
- Output file location
The script uses the macOS version of sed
(sed -i ''
). For Linux systems, you'll need to modify the sed
commands to remove the empty quotes.
Processing user records...
[MODIFIED] Email: user@example.com, Username: oldname -> newname
[UNCHANGED] Email: user2@example.com, Username: user2
[NOT FOUND] Email: unknown@example.com, Username: unknown
Summary:
Total user records processed: 3
Modified records: 1
Unchanged records: 2
Output written to: updated_import.jsonl
Awesome, thank you! 🤩