I have thousands of directories, all of them has this format;
/var/www/vhosts/[USERNAME].company.com/conf/
and i have a file called x.txt, it's content should have
[USERNAME] and some static text...
so when i do dir /var/www/vhosts/*/conf/ , I am getting all the directories that I need to copy the file under, however, I don't know how to grab that [USERNAME] and put it in that file that i need to copy.
All suggestions welcome. I can only use shell scripting on this environment.
Thanks,
... should get you pretty much what you want.
Dennis and Mike make sure you're quoting ${dir}. If there are any directories with spaces this could result in some issues.
For portability's sake I would use "${d%%.*}" for finding the user's name.
Here's another way to do it: