I'm trying to change every first line in all files contained in a parent directory so that they inherit the pathname of the directory that they're in. For example I have a file with the format:
2000-01-18
Tuesday
Livingston
42178
This particular file is in a directory named 18, inside another directory named 01, which is in another directory named 2000, which is in a directory called filesToSort.
I managed to use this code as a console command to change the first line of the file:
perl -pi -w -e 's/2000-01-18/Test/g;' ff_1177818640
This changed the file to
Test
Tuesday
Livingston
42178
Is it possible for me to change the "date" in this command to select all dates, I tried to use it like this:
perl -pi -w -e 's/*/Test/g;' ff_1177818640
But it didn't like that at all.
My current though process is that if I can make this command select all dates in the initial input, then some how find a way to implement the pathname into the second part where I currently have "Test" using something like this:
path=/filesToSort/2000/01/18/ff_1177818640
file=$(basename "$path")
I should in theory be able to run this entire code through my parent directory and all sub directories, therefore changing every date value in the files, which apear on line 1 of every single file, in these directories to mirror the file path that they're in, effectively turning a file that looks like this:
2000-xx-18
Tuesday
Livingston
42178
Contained in directory /filesToSort/2000/01/18 into this:
2000/01/18
Tuesday
Livingston
42178
I'm not sure if I'm just using the sed command wrong here and that there is another command that I should be using instead but I've been trying to get this to work for 4 hours now and I can't seem to nail it. Thanks in advance for the help!