Modifying a list of files based on the filename extension

Viewed 28

I have a .txt file with below entries

filename.type1
filename.type1
filename.type2
filename.type3
filename.type3
filename.type4
filename.type5

For any and all entries of .type1 and .type2, it shall delete and then add respective entry in .txt file as filename_important.type1, or .type2.

Modified file shall look like:

filename_important.type1
filename_important.type1
filename_important.type2
filename.type3
filename.type3
filename.type4
filename.type5
1 Answers

You could use the <replaceregexp> task, for example:

<replaceregexp file="file.txt" byline="true">
    <regexp pattern="\.(type1|type2)$"/>
    <substitution expression="_important.\1"/>
</replaceregexp>
Related