I have like 1000s of files in more than 100s of folders. I need to write one of the folder's name into the file as one of the column.
Directory Structure:
Data -> 000 -> Trajectory -> set of files
Data -> 001 -> Trajectory -> set of files
Data -> 002 -> Trajectory -> set of files
Data -> 003 -> Trajectory -> set of files
. . .
. . .
. . .
Data -> nnn -> Trajectory -> set of files
Every Trajectory folder has more than 100s of files and every file has following columns. Every file has an extension .plt
39.984702,116.318417,0,492,39744.1201851852,2008-10-23,02:53:04
39.984683,116.31845,0,492,39744.1202546296,2008-10-23,02:53:10
39.984686,116.318417,0,492,39744.1203125,2008-10-23,02:53:15
39.984688,116.318385,0,492,39744.1203703704,2008-10-23,02:53:20
39.984655,116.318263,0,492,39744.1204282407,2008-10-23,02:53:25
39.984611,116.318026,0,493,39744.1204861111,2008-10-23,02:53:30
What I am trying to get it put the folder name as one of the column names.
Expected output: for the files in folder with name 000
000 39.984702,116.318417,0,492,39744.1201851852,2008-10-23,02:53:04
000 39.984683,116.31845,0,492,39744.1202546296,2008-10-23,02:53:10
000 39.984686,116.318417,0,492,39744.1203125,2008-10-23,02:53:15
000 39.984688,116.318385,0,492,39744.1203703704,2008-10-23,02:53:20
000 39.984655,116.318263,0,492,39744.1204282407,2008-10-23,02:53:25
000 39.984611,116.318026,0,493,39744.1204861111,2008-10-23,02:53:30
I could not find any near by sample to work around with. Any suggestion will be helpful.
Edit 1: As suggested by @EdChum about using glob But that only allows me to find files with given extension. But my problem here is something else.
In more simple words
rootdir -> subdir_1 -> subdir_2 -> files
Include the name of subdir_1
as col[0]
in all the files present in subdir_2
along with other columns. The files can be appended no need to create a new output file.