r/linux_programming • u/RainbowRedditForum • Apr 21 '22
Script to create subfolders
I'm using Linux and I have a folder called "rttm" which contains some files suffixed with ".rttm" extension, such as:
/rttm/
a.rttm
b.rttm
etc
I'd like to write a shell script that iterates through each file of the "rttm" folder and create a folder called "rttms" where files (which are a copy of their respective in "rttm" folder) are organized in subfolders following a structure like:
/rttms/
/a/
a.rttm
/b/
b.rttm
etc
How could I do?
9
Upvotes
View all comments
Show parent comment
1
u/-_-adam-_- Apr 21 '22
This should get the rest of the way. Might need to escape some of those sequences though. And I don't remember if the filename variable will be the full path or just the filename, so worth double checking
If you wanna avoid sed you could use bash substitutions like in here: https://stackoverflow.com/questions/965053/extract-filename-and-extension-in-bash
You can check out the basename command here if you're not familiar https://linuxize.com/post/basename-command-in-linux/