I'm trying to use hek2mgl's solution to a previous question and am getting an error message I hope you can help me with.
What I am trying to do: rename XML files so they reflect the contents of the identifier element.
This is the exact code I am using:
find . -maxdepth 1 -name 'part*.xml' -exec ./rename_xml.sh {} \; While my rename_xml script looks like this:
#!/bin/bash id=$(xmllint --xpath '//identifier' "$1" | sed -r 's/[^"]+"([^"]+).*/\1/') mv -v "$1" "$id.xml" A sample source XML file looks like this:
<root> <title>title</title> <identifier>001</identifier> </root> I get the following error message when I run the find command.
sed: illegal option -- r usage: sed script [-Ealn] [-i extension] [file ...] sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...] XPath set is empty ./.xml -> .xml My guess it that there are two things happening here - a non-working version of sed (illegal -r option), and a problem with my XPath. How can I change this script to work as intended?