Skip to content

Instantly share code, notes, and snippets.

@pretorh
Last active August 15, 2021 07:05
Show Gist options
  • Save pretorh/53762aafd1cf138cc7d8bfb48e50abc2 to your computer and use it in GitHub Desktop.
Save pretorh/53762aafd1cf138cc7d8bfb48e50abc2 to your computer and use it in GitHub Desktop.
Read changelog items from Android xml resource file
#!/usr/bin/env sh
# skip first few lines in file (xml setup)
# replace explicit new lines in strings with nothing (all newlines are on own line)
# remove leading spaces
# read up to first blank line
tail -n +6 app/src/main/res/values/changelog.xml | \
sed s'|\\n||g' | \
sed s'|^\ *||' | \
sed -e '/^$/,$d'

Shell script using only tail and sed to extract lines from an Android xml string resource file

tail -n +6 app/src/main/res/values/changelog.xml | \
    sed s'|\\n||g'  | \
    sed s'|^\ *||' | \
    sed -e '/^$/,$d'

This parses a changelog.xml file, which is used in-app to display release history. The xml file has the usual resource setup, followed by the version names and notes below them:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="changelog">
        \n
        <A version number, ignored by the script above>:\n
        - A line to describe something in this version\n
        \n
        <another version>:\n
        - Things to\n
        - describe this\n
        - release\n
        \n
        ...

This outputs:

- A line to describe something in this version
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment