<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The eflow blog &#187; sed</title>
	<atom:link href="http://blog.eflow.org/archives/tag/sed/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.eflow.org</link>
	<description>Insert some amazingly witty tagline here</description>
	<lastBuildDate>Fri, 09 Dec 2011 18:59:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
		<item>
		<title>Add Uuids XML Attribute &#8211; Sed Script</title>
		<link>http://blog.eflow.org/archives/238</link>
		<comments>http://blog.eflow.org/archives/238#comments</comments>
		<pubDate>Wed, 20 May 2009 16:50:41 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[openmrs]]></category>
		<category><![CDATA[scripting]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[sh]]></category>
		<category><![CDATA[uuid]]></category>

		<guid isPermaLink="false">http://blog.eflow.org/?p=238</guid>
		<description><![CDATA[OpenMRS recently added a non-null uuid column to every table.  All of our dbunit xml files needed to be updated to insert values for this attribute.  I wrote the following shell script to loop over all xml files under the current folder and add a uuid attribute to all rows that didn&#8217;t have an attribute [...]]]></description>
			<content:encoded><![CDATA[<p>OpenMRS recently added a non-null uuid column to every table.  All of our dbunit xml files needed to be updated to insert values for this attribute.  I wrote the following shell script to loop over all xml files under the current folder and add a uuid attribute to all rows that didn&#8217;t have an attribute already.  There is a bit of logic in there to ignore certain tables because those tables didn&#8217;t actually get any uuids.</p>
<p><span id="more-238"></span></p>
<p>You also can download the <a href="http://blog.eflow.org/wp-content/uploads/2009/05/add_uuids.sh">add_uuids</a> script.</p>
<blockquote>
<pre>
#!/bin/sh

# This script adds a uuid entry to each element in an xml file
# Author: Ben Wolfe - Apr 2009
# http://blog.eflow.org

date
path=`pwd`

# get a flat list of all files under the current directory
f=`ls -RlQ | awk -v PATH=$path '{ \
if ($1 ~ /.*:$/) \
path = substr($1,3,length($1)-4); \
else \
if ($0 ~ /^-/) \
printf("%s%s/%s\n", PATH, path, \
substr($0, match($0,"\".*\"")+1, RLENGTH-2) \
) \
}'`

# create a sed command that adds a generated uuid attribute to all elements that don't contain uuid:
# @UUIDGEN@ needs to get replaced later with the generated uuid
command="/uuid/!{s/\/>/ uuid=\"@UUIDGEN@\"\/>/}"
# ignore rows with &lt;users, &lt;patient, &lt;user_role, &lt;location_tag, &lt;concept_word, &lt;user_privilege, etc because they don't have a uuid column
for word in "&lt;patient " "&lt;user_role " "&lt;location_tag " "&lt;concept_word " "&lt;concept_numeric " "&lt;concept_derived " "&lt;complex_obs " "&lt;role_role " "&lt;role_privilege " "&lt;scheduled_task_config " "&lt;scheduler_task_config_property " "&lt;drug_order " "&lt;concept_complex " "&lt;concept_name_tag_map " "&lt;cohort " "&lt;cohort_member " "&lt;location_tag_map " "&lt;users "
do
   command="/$word/!{$command}"
done

for i in $f
do
#ignore the .svn folder contents
if ! echo $i | grep .svn > /dev/null;
then
    # get the file's extension
    ext=`echo "$i" | awk -F . '{print $NF}'`

    # only execute on xml files
    case $ext in
         xml)
            echo acting on $i

            # blank out the IFS variable so that the "while read line" doesn't delete leading whitespace
            OIFS=$IFS
            IFS=

            while read line
            do
                uuid=`uuidgen`
                newcommand=`echo $command | sed -e "s/@UUIDGEN@/$uuid/"`
                # run the command on the current line
                echo "$line" | sed -e "$newcommand" >> $i.new
            done < $i

            # reset the IFS variable to what it was before
            IFS=$OIFS

            mv -f "$i.new" "$i"

            ;;
        *)
            echo invalid extension: $ext
            ;;
        esac
fi
done

echo "done"
date
</pre>
</blockquote>
 <img src="http://blog.eflow.org/wp-content/plugins/feed-statistics.php?view=1&post_id=238" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.eflow.org/archives/238/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

