Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have seven folders in my folder
meas_2015-06-29_19-03-00 meas_2015-06-29_19-18-28 meas_2015-06-29_19-22-58 meas_2015-06-29_19-26-58 meas_2015-06-29_19-30-58 meas_2015-06-29_19-47-58 meas_2015-06-29_20-39-58
Each of them has inside them xml file,which contains all data about the measurements,including this line
<num_samples>245760</num_samples>
How to write a script that enters each of the folders reads the number of samples and writes them back on the screen?
No it is not working because all the xml files are in subdirectories.Again
milenko@milenko-HP-Compaq-6830s:~/MT8$ ls
EDIs meas_2015-06-29_19-03-00 meas_2015-06-29_19-18-28 meas_2015-06-29_19-22-58 meas_2015-06-29_19-26-58 meas_2015-06-29_19-30-58 meas_2015-06-29_19-47-58 meas_2015-06-29_20-39-58
milenko@milenko-HP-Compaq-6830s:~/MT8$ grep -Ri "num-samples" "*.xml" | wc -l
grep: *.xml: No such file or directory
0
Works but wrong number
grep -Ri num_samples .|wc -l
28
<num_samples>245760</num_samples> in 263_2015-06-29_19-03-00_2015-06-29_19-05-00_R000_2048H.xml
<num_samples>11796480</num_samples> in 263_2015-06-29_19-18-28_2015-06-29_19-19-58_R000_131072H.xml
While szboardstretcher's grep form does work I've realized that instead for something like this I prefer using the find command with -exec for the grep:
And I don't think that it gave you the incorrect number, remove the "| wc -l" term and physically could how many occurrences of num_samples it finds. I bet it is 28.
Not to hi-jack the thread, this is actually related though. Can you, or someone explain why grep won't work with "*.xml" but does work fine with . (DOT), and actually * (STAR), but "*.*" or "*.xml" do not work. Meanwhile the find works fine.
Can you, or someone explain why grep won't work with "*.xml" but does work fine with . (DOT), and actually * (STAR), but "*.*" or "*.xml" do not work. Meanwhile the find works fine.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.