Situation: In Linux, I have a parent folder with almost 100 folders of various names. Each folder has a file ResourceParent.xml
and hundreds of of different version numbers each of which has its own ResourceVer.xml
file. 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. ver548
.
I need to search inside each file for 3 tags .txt|.csv|.xls
and return the information inside these tags into a report.txt file. The tags usually on the same line so I think Grep is ok.
What I've tried:
grep -nr -E ".txt|.csv|.xls" . > /dir/to/the/ReportFile.txt
This takes way too long as it searches in every one of the thousands of directories and produces a lot of unnecessary duplicated data.
Also, 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.
Question: How do I run a linux script to search for tags in a file structure that looks like this: Tags of interest inside .xml files:
".txt|.csv|.xls"
current location:
/dir
File of interest 1:
/dir/par/ResourceParent.xml
File of interest 2:
(need the latest ver number)
/dir/par/ver###/ResourceVer.xml
Needed output file:
ResourceReport.txt
Update
I found ls | tail -1
selects the folder with the greatest ver number. So I think the answer involves this..
find . -type f \( -name "*.csv" -o -name "*.txt" -o -name "*.xls" \)
or ratherfind . -type f \( -name "*.csv" -o -name "*.txt" -o -name "*.xls" \) > /dir/to/the/ReportFile.txt
If you want the full path you could change the.
to/dir/to/the/ReportFile/
. Hope that helps!