Last active
December 17, 2015 12:19
-
-
Save KhasMek/5608689 to your computer and use it in GitHub Desktop.
A quick script to read an xml file from SMSBackup and create a new file based on filtering by a wildcard (date/sender/etc).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # | |
| # A quick script to read an xml file from SMSBackup and create a new file | |
| # based on filtering by a wildcard (date/sender/etc). | |
| # ToDo smarter filtering by tags set in xml. | |
| filename= | |
| wildcard= | |
| new_file= | |
| xsl= | |
| if [ -f "$new_file" ] ; then | |
| echo "$new_file" found. | |
| echo copying to "$new_file".bak | |
| cp $new_file "$new_file".bak | |
| else | |
| touch $new_file | |
| fi | |
| echo "<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>" >> $new_file | |
| if [ -n "$xsl" ]; then | |
| echo "<?xml-stylesheet type=\"text/xsl\" href=\""$xsl"\"?>" >> $new_file | |
| fi | |
| echo "<smses count=xxaazzbdf>" >> $new_file | |
| cat $filename | while read line; do | |
| if [[ $line = *"$wildcard"* ]]; then | |
| echo " $line" >> "$new_file" | |
| fi | |
| done | |
| echo "</smses>" >> "$new_file" | |
| wc=`cat "$new_file" | wc -l | sed 's/^ *//g'` | |
| # -e is needed for sed to run properly on MacOS apparently. | |
| sed -ie "s/xxaazzbdf/\"$wc\"/g" "$new_file" | |
| # cleanup | |
| rm "$new_file"e | |
| echo "File filtering and creation complete!" | |
| echo "copied $wc lines from $filename to $new_file" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment