

You may need to replace -1}"/* with -1}"/ResourceVer.xml. ver100, you will not need to sort the array because it will be in the right order anyway. ver100, you will need to sort the array, but if they are ver001, ver002. If your version numbers are padded so that they sort naturally, for the second command you would be able to use simply: for d in par* a=("$d"/*) grep -HE '.txt|.csv|.xls' -1}"/* done > file

This seems to work (I am getting the last version number) and only takes a couple of seconds on my test directory structure (the first command takes about twice as long). The second one puts the contents of each directory at the par level into an array sorted by version number so that you can search just the last item in the array. grep -include="ResourceParent.xml" -r -E '.txt|.csv|.xls' > fileįor d in par* a=("$d"/*) b=($(sort -V > file I found ls | tail -1 selects the folder with the greatest ver number. (need the latest ver number) /dir/par/ver#/ResourceVer.xml xml files: ".txt|.csv|.xls"įile of interest 1: /dir/par/ResourceParent.xml Question: How do I run a linux script to search for tags in a file structure that looks like this:

This takes way too long as it searches in every one of the thousands of directories and produces a lot of unnecessary duplicated data.Īlso, I've tried to go into each folder depending on what I'm looking for and running this script, which is a bit better re reduced duplicates and more relevant data, but it is still too cumbersome. What I've tried: grep -nr -E ".txt|.csv|.xls". The tags usually on the same line so I think Grep is ok. txt|.csv|.xls and return the information inside these tags into a report.txt file. I need to search inside each file for 3 tags. I am interested in both ResourceParent.xml in the 1st level folder and the ResourceVer.xml in the LATEST version folder (highest number) e.g. Each folder has a file ResourceParent.xml and hundreds of of different version numbers each of which has its own ResourceVer.xml file. Situation: In Linux, I have a parent folder with almost 100 folders of various names.
