Writing a Bash script
There are files with such names:
0000_index.txt
GLN-DAN_vf_119_0000.txt
GLN-DAN_vf_119_0001.txt
GLN-DAN_vf_119_0002.txt
GLN-DAN_vf_119_0003.txt
You need to change their names by bringing them in this form:
0000_index.txt > GLN-DAN_vf_119_0000.txt
GLN-DAN_vf_119_0000.txt > GLN-DAN_vf_119_0001.txt
GLN-DAN_vf_119_0001.txt > GLN-DAN_vf_119_0002.txt
GLN-DAN_vf_119_0002.txt > GLN-DAN_vf_119_0003.txt
GLN-DAN_vf_119_0003.txt > GLN-DAN_vf_119_0004.txt
The task is repeated periodically.What can change in repeated tasks and requires attention when writing a script:
In the original file names, starting from the second and later, before the last emphasis, the same text is always within one task, and it can contain any characters that are possible in the file name, in any order.When renamed, this part (up to the last emphasis) must be taken identical.The last emphasis is present in all tasks and can be taken as the foundation for the creation of the max.After the last emphasis, there is always a regular numeration, starting with 0.The number of numeration signs is always the same within one task, but it can vary in repeated tasks.The number of characters that are used in the original names of the files, starting from the second to the next, must be applied to the re-name.The first source file must always be renamed, regardless of its name.You can attach to the absence in its name of the re-name mask, present in the names of the other files (up to the last emphasis).
Client's review of cooperation with Oleh Kovalievskyi
Writing a Bash scriptEverything at the highest level. performed greatly. Glad for pleasant collaboration.
Freelancer's review of cooperation with Alexander Perkov
Writing a Bash scriptThe customer has placed a clear TZ, all the conditions are met.
I hope for further cooperation.
-
1282 23 0 I do the task according to TZ. I have more than 10 years of experience using Linux.
-
Можете так делать
mkdir -p new |ls | grep -E '[0-9]{4}' | awk '{printf "mv %10s new/GLN-DAN_vf_119_%04d.txt\n",$1,i++;}' | sh
-
Вітаю. Чи правильно я зрозумів що перший файл завжди буде мати назву 0000_index.txt а всі інші будуть мати закінчення _xxxx.txt ?
-
Current freelance projects in the category Linux & Unix
Deployment of a Ruby on Rails project on VPS + Inbound Email RoutingNeed help deploying a platform for automating requests for public information (based on the open-source engine Alaveteli). The project works as a mail router: it generates unique email addresses for each request, sends them to government agencies, and receives responses back to… DevOps, Linux & Unix ∙ 3 days 4 hours back ∙ 11 proposals |