Reputation: 83
I'm trying to replace
</url></loc>
with
</loc></url>
in all my files but nothing seems to be working. Is there a way to do this via command line, perl, etc.? Any help would be greatly appreciated.
Upvotes: 0
Views: 162
Reputation: 320
find . -type f -name "yourname*" -exec sed -i 's/<\/url><\/loc>/<\/loc><\/url>/g' '{}' ';'
Upvotes: 0
Reputation: 212248
Note that many versions of sed
do not recognize -i
. But you can do exactly the same with perl:
find . -exec perl -i -pe 's|(</url>)(</loc>)|$2$1|g' {} \;
Perl has a big advantage over sed in that it will be much easier to expand this to include occurrences of the two tags that are spread over multiple lines.
perl -0777 -i -pe 's|(</url>)(\s*)(</loc>)|$3$2$1|g'
Upvotes: 4
Reputation: 4209
Use sed:
sed -i 's/<\/url><\/loc>/<\/loc><\/url>/g' yourfiles.*
To replace other tags:
sed -E -i 's/<\/(url|what|ever)><\/(loc|any|other)>/<\/\2><\/\1>/g' yourfiles.*
Upvotes: 1