Hello!
I need to realize such task.
1. In my user's home dir I have
folder1;
2. In
folder1 I have some (various count)
subfolders with random names;
3. In these subfolders I have one file
anyname.pdf (various name in each subfolder) and file
content.txt (constant name in each subfolder)
## If in subfolder more than one .pdf or more than one .txt file, I must miss this subfolder (move it to Folder3 - it's one of the folders of my user's home dir) ;
So,
4. I must to scan every
subfolders in folder1,
enter in each one;
5. If this subfolder has more than one .pdf file and more than one .txt file, I must go to next subfolder (with moving this subfolder to Folder3);
6. In "good" subfolders I must take file content.txt;
7. It has such structure:
dfdf{some trash}wqwq
begin_of_useful_info
info info ... info
end_of_useful_info
dfdf{some trash}wqwq
8. In this file
content.txt I must find and cut only "
useful_info" (between begin_of_useful_info and end_of_useful_info,including it):
begin_of_useful_info
info info ... info
end_of_useful_info
( begin_of_useful_info and end_of_useful_info is key-words on each content.txt, it must be cutted too)
9. this info I must put in new .txt file with name as .pdf file in
this subfolder!
Example:
In folder1/4323353/ I have files GHTY34.pdf and content.txt. So, after operation I must get a file GHTY34.txt with useful_info)
10. delete parsed file content.txt
(so, now I have again two files in subfolder somename.pdf and somename.txt)
11. then I must copy files .pdf and new .txt with similar names somewhere, for example in folder2 (my user's home dir) and delete analized subfolder.
12. Go to next subfolder.
That's all
![Smilie Smilie](https://www.unix.com/images/smilies/smile.gif)
Thanks!
---------- Post updated at 01:55 PM ---------- Previous update was at 11:53 AM ----------
I write not workable code, it's just a plan
PHP Code:
#!/bin/sh\
cd folder1
find -type d | while read directory
do
cd "${directory#"./"}"
# check numbers of .txt and .pdf
# create new file .txt and remove old .txt file
cp pdffile ../../folder2/pdffile
cp txtfile ../../folder2/txtfile
mv "${directory#"./"}" ../../folder3/"${directory#"./"}"
cd ..
done
maybe it can help to understand the idea that I want to do.