Convert .../($var1|$var2)/... regex to string
Hello,
In one part of my shell program I need to translate many of lines in the following pattern : Code:
/(folder1|...|folderN)/(sub1|...|subN)/.../(file1|...|fileN) Code:
/folder1/sub1/file1 |
Hi and welcome to LQ.
Can you post the actual example of your naming conventions? Do the names of the directories/files differ only in the appended number? |
Here are some of them :
Code:
/(ar|az|dua|en|fa|fr)/(index|index2).php |
Now you've confused me. That's not exactly what you posted in the original post.
Can you post the desired output of the sample above? |
Thank you for your answer !
Where's the confusion? desired output : Code:
/ar/index.php |
Well, this is a challenging one!
A proper solution would likely involve parsing the lines and storing each part separately into arrays, which would be re-built into the desired output, or something like that. It would take some time to figure out. I do have a quick hack solution, but I don't particularly recommend it. Code:
text='/(ar|az|dua|en|fa|fr)/administrator/(index|index2).php' It also won't work correctly if any part of the original line contains whitespace, or if there happen to be '()|' characters that aren't part of the expansion pattern. (Incidentally, I tried to use parameter substitutions instead of tr, but there seems to be a bug in my bash that keeps the substitution to "}" from being handled correctly.) |
Quote:
Code:
cat text.txt Code:
#!/usr/bin/env python |
All times are GMT -5. The time now is 02:40 PM. |