Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 1113  / 2 Years ago, sat, july 16, 2022, 9:00:27

I have one big directory, that contains many subdirectories whose names are staring with 13xxx,10xxx,11xxx and so on. These directories contains text files with a name my_file.txt.
Now the problem is, I want to change the files in the directories 13xxx and 11xxx only and don't want to touch files in 10xxx directories.
I am trying to search directories with:


[ -d "13*"] && ..
[ -d "13"*] && ..

But seems like it doesn't work like this.
Can anyone provide a small code that solves this riddle?


More From » bash

 Answers
5

You can use a for-loop and globbing like:


for d in 1[13]*; do
do_something "$d/my_file.txt";
done

or


for f in 1[13]*/my_file.txt; do
do_something "$f";
done

[#762] Monday, July 18, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
percol

Total Points: 493
Total Questions: 116
Total Answers: 107

Location: Taiwan
Member since Mon, Sep 6, 2021
3 Years ago
percol questions
Thu, Sep 29, 22, 07:42, 2 Years ago
Tue, May 30, 23, 19:16, 12 Months ago
Wed, Aug 18, 21, 02:15, 3 Years ago
;