Create simple script

Dear all,

I have a directory named A and some subdirectories named B, C, D with .xml files. I want to use the following command to strip the file.

sed -re ':start s/<[^>]*>//g; /</ {N; b start}' file.xml > file.xml

At the same time, I want to remove the blank lines using

sed '/^$/d'

How can I create a simple script for all files?

Doesn't work that way. You shouldn't write to the same file you're reading, you'll truncate it.

If your sed's work, then:

for FILE in *.xml
do
        sed -re ':start s/<[^>]*>//g; /</ {N; b start}' "$FILE" > /tmp/$$
        sed '/^$/d' < /tmp/$$ > "$FILE".new
done

rm -f /tmp/$$

Remove the '.new' once you've tested it and are sure it does what you want. It's all too easy to destroy your originals by accident when you edit them automatically.

thank you. It works, but with some problems! The script removes the tags bat not the blank lines.

Could you tell me also how can I proccess the xml files in the subdirectories?
Thank you in advance.

Are you sure they're actually blank? They could have a single space or something.

find . -iname '*.xml' | while read FILE
do
        sed -re ':start s/<[^>]*>//g; /</ {N; b start}' "$FILE" > /tmp/$$
        sed '/^[ \t]*$/d' < /tmp/$$ > "$FILE".new
done

Thank you! It works! The lines seems to be empty, but when I am trying to open them with vi, there is ^M character. Do you know how can I remove it?
Thanks a lot for your help.

find . -iname '*.xml' | while read FILE
do
        sed -re ':start s/<[^>]*>//g; /</ {N; b start}' "$FILE" > /tmp/$$
        tr -d '\r' | sed '/^[ \t]*$/d' < /tmp/$$ > "$FILE".new
done

Thank you very much for your helping. I tried and it works! Could you tell me please how the new file can be created in a other location. For example, I have the main dir, called DIR1 with subdirs called EX1, EX2, A1, A2 ....The xml files are located in subdirs. This dir is on C drive. I want to create a new dir named DIR1 with the same stucture and only the new files in F drive.

Thank you in advance!