I�m trying to replace the 2 last folders name in a list of directories with a new string, but I�m don�t know which regex to apply.
Directories list:
C/my user/documents/games & music
C/my user/documents/photos 09-24-2008
C/my user/settings/config ?1_2
* The last folder may have characters such as -, _, & or ?
Example with the firt line
sed 's/\/documents\/games & music/\/final folder/g' infile
Many thanks devtakh, it works. Many thanks posix either.
Sorry, my last question regarding this, I didn�t realize about this part before.
I can see your script works, but now I found that one or two directories contain only 2 subfolder levels.
How to insert an if statement within sed to match the last 2 folders if the entire string contains 3 subfolders and match only the very last folder if entire string cotainds only 2 subfolders?
I mean:
C/my user/documents/photos 09-24-2008 (If has 3 subfolders)
then match desired
C/my user/documents/photos 09-24-2008 (match last 2 subfolders)
C/my user/travels (If has 2 subfolders)
then match desired
C/my user/travels (match only last subfolder)