[opensuse-support] Scripting problem
Hi, I have a scripting problem. I want to create relative paths. Googling told me I need to use: realpath --relative-to=something someotherthing But I can't find the correct concoction. I have the following structure (TV recordings): /home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/notes /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg From that list of absolute paths, I want to produce a relative one: 3_MyBook_Videos/Lore.mpeg or ./3_MyBook_Videos/Lore.mpeg ../3_MyBook_Videos/Big Bang/notes ../../3_MyBook_Videos//Big Bang/Season 6/06x01.mpeg I got a headache, but no working solution. Example: cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/" "/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg" ../../../../data/My_Book/Fusion/Videos/Lore.mpeg cer@Isengard:~/FusionTst/Videos> cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg" "/home/cer/FusionTst/Videos/" ../../../../../home/cer/FusionTst/Videos cer@Isengard:~/FusionTst/Videos> Previous to that I was using a method of my own that worked on some, failed on others. Then I stumbled into this "realpath" command, but I can not make it work as I need. -- Cheers / Saludos, Carlos E. R. (from 15.0 x86_64 at Telcontar)
09.03.2019 17:51, Carlos E. R. пишет:
Hi,
I have a scripting problem.
You have realpath question. You really are not a newbie to not understand the difference and put in the most meaningless subject possible.
I want to create relative paths. Googling told me I need to use:
realpath --relative-to=something someotherthing
But I can't find the correct concoction.
I have the following structure (TV recordings):
/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/notes /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg
From that list of absolute paths, I want to produce a relative one:
3_MyBook_Videos/Lore.mpeg or ./3_MyBook_Videos/Lore.mpeg ../3_MyBook_Videos/Big Bang/notes ../../3_MyBook_Videos//Big Bang/Season 6/06x01.mpeg
I got a headache, but no working solution.
Example:
cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/" "/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg" ../../../../data/My_Book/Fusion/Videos/Lore.mpeg cer@Isengard:~/FusionTst/Videos>
I bet you have symlinks in path.
cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg" "/home/cer/FusionTst/Videos/" ../../../../../home/cer/FusionTst/Videos cer@Isengard:~/FusionTst/Videos>
And what exactly should the above invocation achieve?
Previous to that I was using a method of my own that worked on some, failed on others. Then I stumbled into this "realpath" command, but I can not make it work as I need.
On 09/03/2019 16.22, Andrei Borzenkov wrote:
09.03.2019 17:51, Carlos E. R. пишет:
Hi,
I have a scripting problem.
You have realpath question. You really are not a newbie to not understand the difference and put in the most meaningless subject possible.
No. It doesn't matter to me if the answer does not use "realpath".
I want to create relative paths. Googling told me I need to use:
realpath --relative-to=something someotherthing
But I can't find the correct concoction.
I have the following structure (TV recordings):
/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/notes /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg
From that list of absolute paths, I want to produce a relative one:
3_MyBook_Videos/Lore.mpeg or ./3_MyBook_Videos/Lore.mpeg ../3_MyBook_Videos/Big Bang/notes ../../3_MyBook_Videos//Big Bang/Season 6/06x01.mpeg
I got a headache, but no working solution.
Example:
cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/" "/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg" ../../../../data/My_Book/Fusion/Videos/Lore.mpeg cer@Isengard:~/FusionTst/Videos>
I bet you have symlinks in path.
Yes, so? Ah. 3_MyBook_Videos -> /data/My_Book/Fusion/Videos/ I don't care if it is a symlink, I want to obtain "3_MyBook_Videos/Lore.mpeg" as the result, if not with "realpath" then with something else.
cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg" "/home/cer/FusionTst/Videos/" ../../../../../home/cer/FusionTst/Videos cer@Isengard:~/FusionTst/Videos>
And what exactly should the above invocation achieve?
You can see what it prints. So, you have no answer? This is without synmlinks. cer@Isengard:~/FusionTst/Videos> tree 3_MyBook_VideosTst/ 3_MyBook_VideosTst/ ├── Big Bang │ ├── notas │ ├── Season 1 │ │ ├── episode dos.mpeg │ │ ├── episode tres.mpeg │ │ └── episode uno.mpeg │ └── Season 2 │ ├── episode dos.mpeg │ ├── episode tres.mpeg │ └── episode uno.mpeg ├── Big Poof │ ├── notas │ ├── Season 1 │ │ ├── episode dos.mpeg │ │ ├── episode tres.mpeg │ │ └── episode uno.mpeg │ └── Season 2 │ ├── episode dos.mpeg │ ├── episode tres.mpeg │ └── episode uno.mpeg └── notas cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/" "/home/cer/FusionTst/Videos/3_MyBook_VideosTst/Notes" 3_MyBook_VideosTst/Notes Ok cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/" "/home/cer/FusionTst/Videos/3_MyBook_VideosTst/Big Bang/notas" 3_MyBook_VideosTst/Big Bang/notas cer@Isengard:~/FusionTst/Videos> Wrong, I want: ../3_MyBook_VideosTst/Big Bang/notas cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/Big Bang" "/home/cer/FusionTst/Videos/3_MyBook_VideosTst/Big Bang/notas" ../3_MyBook_VideosTst/Big Bang/notas cer@Isengard:~/FusionTst/Videos> Yes. cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/3_MyBook_VideosTst/Big Bang/Season 2/" "/home/cer/FusionTst/Videos/3_MyBook_VideosTst/Big Bang/Season 2/episode uno.mpeg" episode uno.mpeg cer@Isengard:~/FusionTst/Videos> Wrong, I want: ../../3_MyBook_VideosTst/episode uno.mpeg So realpath --relative-to={Real_Path} {Real_path/file} is not it. -- Cheers / Saludos, Carlos E. R. (from 15.0 x86_64 at Telcontar)
Carlos, et al -- ...and then Carlos E. R. said... % % On 09/03/2019 16.22, Andrei Borzenkov wrote: % > 09.03.2019 17:51, Carlos E. R. ??????????: % >> ... % >> I have the following structure (TV recordings): % >> % >> /home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg % >> /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/notes % >> /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg % >> % >> From that list of absolute paths, I want to produce a relative one: % >> % >> 3_MyBook_Videos/Lore.mpeg or ./3_MyBook_Videos/Lore.mpeg % >> ../3_MyBook_Videos/Big Bang/notes % >> ../../3_MyBook_Videos//Big Bang/Season 6/06x01.mpeg ... % % cer@Isengard:~/FusionTst/Videos> tree 3_MyBook_VideosTst/ % 3_MyBook_VideosTst/ % ????????? Big Bang % ??? ????????? notas % ??? ????????? Season 1 % ??? ??? ????????? episode dos.mpeg % ??? ??? ????????? episode tres.mpeg % ??? ??? ????????? episode uno.mpeg % ??? ????????? Season 2 % ??? ????????? episode dos.mpeg % ??? ????????? episode tres.mpeg % ??? ????????? episode uno.mpeg % ????????? Big Poof % ??? ????????? notas % ??? ????????? Season 1 % ??? ??? ????????? episode dos.mpeg % ??? ??? ????????? episode tres.mpeg % ??? ??? ????????? episode uno.mpeg % ??? ????????? Season 2 % ??? ????????? episode dos.mpeg % ??? ????????? episode tres.mpeg % ??? ????????? episode uno.mpeg % ????????? notas [snip] I find myself wondering if you have reduced this to a trivial case. I wasn't patient enough to follow your various realpath(1) examples, so I've snipped them, but as you say the tool isn't important. It seems to me that you could just use find(1) to list your files. But I know you know that, so ... it must not be that simple :-) If there's more than the tree above, please lay out a fuller structure. Please also point out where you want to be (perhaps multiple places?) and the result you want to see that you carefully construct manually so that we can back into the engineering :-) And, just because I'm curious, I wonder why you specifically want relative paths rather than absolute paths, which certainly keep life simple... HTH & HANW :-D -- David T-G See http://justpickone.org/davidtg/email/ See http://justpickone.org/davidtg/tofu.txt -- To unsubscribe, e-mail: opensuse-support+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-support+owner@opensuse.org
Le 10/03/2019 à 02:57, David T-G a écrit :
And, just because I'm curious, I wonder why you specifically want relative paths rather than absolute paths, which certainly keep life simple...
I dunno if it's the Carlos problem, but absolute path are a real problem when archiving on an usb disk, the link still resolve to the original data, not the copied one jdd -- http://dodin.org -- To unsubscribe, e-mail: opensuse-support+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-support+owner@opensuse.org
On 10/03/2019 02.57, David T-G wrote:
Carlos, et al --
% cer@Isengard:~/FusionTst/Videos> tree 3_MyBook_VideosTst/ % 3_MyBook_VideosTst/ % ????????? Big Bang % ??? ????????? notas % ??? ????????? Season 1 % ??? ??? ????????? episode dos.mpeg % ??? ??? ????????? episode tres.mpeg % ??? ??? ????????? episode uno.mpeg % ??? ????????? Season 2 % ??? ????????? episode dos.mpeg % ??? ????????? episode tres.mpeg % ??? ????????? episode uno.mpeg % ????????? Big Poof % ??? ????????? notas % ??? ????????? Season 1 % ??? ??? ????????? episode dos.mpeg % ??? ??? ????????? episode tres.mpeg % ??? ??? ????????? episode uno.mpeg % ??? ????????? Season 2 % ??? ????????? episode dos.mpeg % ??? ????????? episode tres.mpeg % ??? ????????? episode uno.mpeg % ????????? notas [snip]
I find myself wondering if you have reduced this to a trivial case.
For testing. It contains all the cases of the real thing. Well, except that the real thing has some directories and files with double spaces - and that caused a bug that took an hour at least to find out. I have no control at all on the names, so... I will add some spaces to the test structure :-p
I wasn't patient enough to follow your various realpath(1) examples, so I've snipped them, but as you say the tool isn't important.
It seems to me that you could just use find(1) to list your files. But I know you know that, so ... it must not be that simple :-)
I do use find to list the files in the script, yes :-) It is a script using recursion.
If there's more than the tree above, please lay out a fuller structure. Please also point out where you want to be (perhaps multiple places?) and the result you want to see that you carefully construct manually so that we can back into the engineering :-)
This small tree is what I use for testing the script, and covers all cases - files are in fact zero bytes: cer@Isengard:~/FusionTst/Videos> tree -A 3_MyBook_VideosTst/ 3_MyBook_VideosTst/ ├── Big Bang │ ├── notas │ ├── Season 1 │ │ ├── episode dos.mpeg │ │ ├── episode tres.mpeg │ │ └── episode uno.mpeg │ └── Season 2 │ ├── episode dos.mpeg │ ├── episode tres.mpeg │ └── episode uno.mpeg ├── Big Poof │ ├── notas │ ├── Season 1 │ │ ├── episode dos.mpeg │ │ ├── episode tres.mpeg │ │ └── episode uno.mpeg │ └── Season 2 │ ├── episode dos.mpeg │ ├── episode tres.mpeg │ └── episode uno.mpeg └── notas 6 directories, 15 files cer@Isengard:~/FusionTst/Videos> The purpose is to create a duplicate tree of the above (directory "Videos/3_MyBook_VideosTst/"), at "Videos/" where directories are real directories and files are symlinks. There is a an option to "cp" that would do that, yes. But my script also does purging of dead links and handles existing files on the target (unfinished part)
And, just because I'm curious, I wonder why you specifically want relative paths rather than absolute paths, which certainly keep life simple...
Good question. The "full path" version of the script is already working fine, so why bother? Maybe because relative paths work on backups or if I copy/move the structure. -- Cheers / Saludos, Carlos E. R. (from 15.0 x86_64 at Telcontar)
09.03.2019 21:45, Carlos E. R. пишет:
On 09/03/2019 16.22, Andrei Borzenkov wrote:
09.03.2019 17:51, Carlos E. R. пишет:
Hi,
I have a scripting problem.
You have realpath question. You really are not a newbie to not understand the difference and put in the most meaningless subject possible.
No. It doesn't matter to me if the answer does not use "realpath".
Then you need to ask the right question. Nobody seems to understand what you are trying to achieve.
I want to create relative paths. Googling told me I need to use:
realpath --relative-to=something someotherthing
But I can't find the correct concoction.
I have the following structure (TV recordings):
/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/notes /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg
From that list of absolute paths, I want to produce a relative one:
Relative to what? /home/cer/FusionTst/Videos? Well echo /home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg | cut -d/ -f6-
3_MyBook_Videos/Lore.mpeg or ./3_MyBook_Videos/Lore.mpeg ../3_MyBook_Videos/Big Bang/notes ../../3_MyBook_Videos//Big Bang/Season 6/06x01.mpeg
I got a headache, but no working solution.
Example:
cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/" "/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg" ../../../../data/My_Book/Fusion/Videos/Lore.mpeg cer@Isengard:~/FusionTst/Videos>
I bet you have symlinks in path.
Yes, so?
Did you try to read documentation for realpath as was already hinted? --><-- ‘realpath’ expands all symbolic links and resolves references to ‘/./’, ‘/../’ and extra ‘/’ characters. --><--
Ah.
3_MyBook_Videos -> /data/My_Book/Fusion/Videos/
So the realpath behaves correctly.
I don't care if it is a symlink,
Computers do not read your mind. They do exactly what you tell them to do.
I want to obtain "3_MyBook_Videos/Lore.mpeg" as the result, if not with "realpath" then with something else.
I gave you one solution above. Another solution would be to read realpath documentation and use --no-symlinks option.
cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg" "/home/cer/FusionTst/Videos/" ../../../../../home/cer/FusionTst/Videos cer@Isengard:~/FusionTst/Videos>
And what exactly should the above invocation achieve?
You can see what it prints.
And?
So, you have no answer?
To what?
This is without synmlinks.
cer@Isengard:~/FusionTst/Videos> tree 3_MyBook_VideosTst/ 3_MyBook_VideosTst/ ├── Big Bang │ ├── notas │ ├── Season 1 │ │ ├── episode dos.mpeg │ │ ├── episode tres.mpeg │ │ └── episode uno.mpeg │ └── Season 2 │ ├── episode dos.mpeg │ ├── episode tres.mpeg │ └── episode uno.mpeg ├── Big Poof │ ├── notas │ ├── Season 1 │ │ ├── episode dos.mpeg │ │ ├── episode tres.mpeg │ │ └── episode uno.mpeg │ └── Season 2 │ ├── episode dos.mpeg │ ├── episode tres.mpeg │ └── episode uno.mpeg └── notas
cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/" "/home/cer/FusionTst/Videos/3_MyBook_VideosTst/Notes" 3_MyBook_VideosTst/Notes
Ok
cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/" "/home/cer/FusionTst/Videos/3_MyBook_VideosTst/Big Bang/notas" 3_MyBook_VideosTst/Big Bang/notas cer@Isengard:~/FusionTst/Videos>
Wrong, I want:
../3_MyBook_VideosTst/Big Bang/notas
And how should we or realpath know what you want? Start with explaining why you suddenly need ".." in the second case and how to determine when you need ".." using rules that can be translated into computer commands. Oh, and why it is OK to *not* have ".." in the first case.
On 10/03/2019 05.20, Andrei Borzenkov wrote:
09.03.2019 21:45, Carlos E. R. пишет:
On 09/03/2019 16.22, Andrei Borzenkov wrote:
09.03.2019 17:51, Carlos E. R. пишет:
Hi,
I have a scripting problem.
You have realpath question. You really are not a newbie to not understand the difference and put in the most meaningless subject possible.
No. It doesn't matter to me if the answer does not use "realpath".
Then you need to ask the right question. Nobody seems to understand what you are trying to achieve.
Then ask. I do what I can. I'm not god, not even a perfect human being.
I want to create relative paths. Googling told me I need to use:
realpath --relative-to=something someotherthing
But I can't find the correct concoction.
I have the following structure (TV recordings):
/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/notes /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg
From that list of absolute paths, I want to produce a relative one:
Relative to what? /home/cer/FusionTst/Videos? Well
No. Relative to the directory where each symlink lives, which is not the same for each one. Given this tree: /home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/notes /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg I want to generate these relative symlinks in this replica tree: Lore.mpeg --> 3_MyBook_Videos/Lore.mpeg or Lore.mpeg --> ./3_MyBook_Videos/Lore.mpeg Big Bang/notes --> ../3_MyBook_Videos/Big Bang/notes Big Bang/Season 6/06x01.mpeg --> ../../3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg I already have a script that generates the tree using "absolute" paths - not caring that "3_MyBook_Videos" is in fact another symlink. I then wanted to do it with relative symlinks. I did it with code of my own that failed in some of the cases, so I googled for some ready to paste solution, and hit upon "realpath". This also failed, I do not understand the man page, got a headache and a block, so I asked here. Not that difficult to understand.
echo /home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg | cut -d/ -f6-
3_MyBook_Videos/Lore.mpeg or ./3_MyBook_Videos/Lore.mpeg ../3_MyBook_Videos/Big Bang/notes ../../3_MyBook_Videos//Big Bang/Season 6/06x01.mpeg
I got a headache, but no working solution.
Example:
cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/" "/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg" ../../../../data/My_Book/Fusion/Videos/Lore.mpeg cer@Isengard:~/FusionTst/Videos>
I bet you have symlinks in path.
Yes, so?
Did you try to read documentation for realpath as was already hinted?
I did not understand it.
--><-- ‘realpath’ expands all symbolic links and resolves references to ‘/./’, ‘/../’ and extra ‘/’ characters. --><--
Ah.
3_MyBook_Videos -> /data/My_Book/Fusion/Videos/
So the realpath behaves correctly.
I don't care if it is a symlink,
Computers do not read your mind. They do exactly what you tell them to do.
Which is why I ask humans here. I obviously know that I'm doing it wrong. -- Cheers / Saludos, Carlos E. R. (from 15.0 x86_64 at Telcontar)
10.03.2019 17:40, Carlos E. R. пишет:
Given this tree:
/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/notes /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg
I want to generate these relative symlinks in this replica tree:
Lore.mpeg --> 3_MyBook_Videos/Lore.mpeg or Lore.mpeg --> ./3_MyBook_Videos/Lore.mpeg
Big Bang/notes --> ../3_MyBook_Videos/Big Bang/notes
Big Bang/Season 6/06x01.mpeg --> ../../3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg
I already have a script that generates the tree using "absolute" paths - not caring that "3_MyBook_Videos" is in fact another symlink. I then wanted to do it with relative symlinks. I did it with code of my own that failed in some of the cases, so I googled for some ready to paste solution, and hit upon "realpath". This also failed, I do not understand the man page, got a headache and a block, so I asked here.
Not that difficult to understand.
$ cat /tmp/foo /home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/notes /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg $ sed 's#/home/cer/FusionTst/Videos/3_MyBook_Videos/##;/.*\/.*/{h;s#[^/][^/]*/#../#g; s#\(.*/\).*$#\1#;x};s#^#3_MyBook_Videos/#;x;G;s#\n##' < /tmp/foo 3_MyBook_Videos/Lore.mpeg ../3_MyBook_Videos/Big Bang/notes ../../3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg
On 10/03/2019 22.01, Andrei Borzenkov wrote:
10.03.2019 17:40, Carlos E. R. пишет:
Given this tree:
/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/notes /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg
I want to generate these relative symlinks in this replica tree:
Lore.mpeg --> 3_MyBook_Videos/Lore.mpeg or Lore.mpeg --> ./3_MyBook_Videos/Lore.mpeg
Big Bang/notes --> ../3_MyBook_Videos/Big Bang/notes
Big Bang/Season 6/06x01.mpeg --> ../../3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg
I already have a script that generates the tree using "absolute" paths - not caring that "3_MyBook_Videos" is in fact another symlink. I then wanted to do it with relative symlinks. I did it with code of my own that failed in some of the cases, so I googled for some ready to paste solution, and hit upon "realpath". This also failed, I do not understand the man page, got a headache and a block, so I asked here.
Not that difficult to understand.
$ cat /tmp/foo /home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/notes /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg $ sed 's#/home/cer/FusionTst/Videos/3_MyBook_Videos/##;/.*\/.*/{h;s#[^/][^/]*/#../#g; s#\(.*/\).*$#\1#;x};s#^#3_MyBook_Videos/#;x;G;s#\n##' < /tmp/foo 3_MyBook_Videos/Lore.mpeg ../3_MyBook_Videos/Big Bang/notes ../../3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg
Thanks, I'll try. Unfortunately, I don't understand that (regex?), I will be unable to maintain it. I'll have another go at trying to code something myself :-) -- Cheers / Saludos, Carlos E. R. (from 15.0 x86_64 at Telcontar)
On 3/10/2019 7:40 AM, Carlos E. R. wrote:
I want to create relative paths. Googling told me I need to use: realpath --relative-to=something someotherthing But I can't find the correct concoction. I have the following structure (TV recordings): /home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/notes /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg
From that list of absolute paths, I want to produce a relative one: This is without synmlinks.
cer@Isengard:~/FusionTst/Videos> tree 3_MyBook_VideosTst/ 3_MyBook_VideosTst/ ├── Big Bang │ ├── notas (copy of Big Bank/notes, above?) │ ├── Season 1 │ │ ├── episode dos.mpeg │ │ ├── episode tres.mpeg │ │ └── episode uno.mpeg │ └── Season 2 │ ├── episode dos.mpeg │ ├── episode tres.mpeg │ └── episode uno.mpeg └── notas (where does this come from?)
--- Where did Lore.mpeg go? With season 6/06x01.mpeg -- what filename does that map to? "BB/Seas6/ep six.mpeg ?" (abbreviated a bit) ---- So you want to create your own directory structure where the source is the semi-flat structure probably created by some download program? BTW, Are these all on the same volume such that hardlinks are also an option? Just curious if that's an option, dunno if they would be useful. -- To unsubscribe, e-mail: opensuse-support+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-support+owner@opensuse.org
On 19/03/2019 22.07, L A Walsh wrote:
On 3/10/2019 7:40 AM, Carlos E. R. wrote:
I want to create relative paths. Googling told me I need to use: realpath --relative-to=something someotherthing But I can't find the correct concoction. I have the following structure (TV recordings): /home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/notes /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg
From that list of absolute paths, I want to produce a relative one: This is without synmlinks.
cer@Isengard:~/FusionTst/Videos> tree 3_MyBook_VideosTst/ 3_MyBook_VideosTst/ ├── Big Bang │ ├── notas (copy of Big Bank/notes, above?) │ ├── Season 1 │ │ ├── episode dos.mpeg │ │ ├── episode tres.mpeg │ │ └── episode uno.mpeg │ └── Season 2 │ ├── episode dos.mpeg │ ├── episode tres.mpeg │ └── episode uno.mpeg └── notas (where does this come from?)
--- Where did Lore.mpeg go? With season 6/06x01.mpeg -- what filename does that map to? "BB/Seas6/ep six.mpeg ?" (abbreviated a bit)
No, it is a movie, not an episode. I used that one for the example because the name was short :-) https://en.wikipedia.org/wiki/Lore_(film)
---- So you want to create your own directory structure where the source is the semi-flat structure probably created by some download program?
No, the structure is the same as made by the recording program. They are not downloads, but automatic recordings. So, not under my control, except where I place the root.
BTW, Are these all on the same volume such that hardlinks are also an option? Just curious if that's an option, dunno if they would be useful.
No, they are different disks. Simply when the main disk fills, I move movies to the second disk. I want to use relative links because when I mount both disks remotely (nfs, sshfs) the absolute paths are no longer valid and the links fail. -- Cheers / Saludos, Carlos E. R. (from 15.0 x86_64 at Telcontar)
* Carlos E. R.
Hi,
I have a scripting problem.
I want to create relative paths. Googling told me I need to use:
realpath --relative-to=something someotherthing
But I can't find the correct concoction.
I have the following structure (TV recordings):
/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/notes /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg
From that list of absolute paths, I want to produce a relative one:
3_MyBook_Videos/Lore.mpeg or ./3_MyBook_Videos/Lore.mpeg ../3_MyBook_Videos/Big Bang/notes ../../3_MyBook_Videos//Big Bang/Season 6/06x01.mpeg
I got a headache, but no working solution.
Example:
cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/" "/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg" ../../../../data/My_Book/Fusion/Videos/Lore.mpeg cer@Isengard:~/FusionTst/Videos>
cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg" "/home/cer/FusionTst/Videos/" ../../../../../home/cer/FusionTst/Videos cer@Isengard:~/FusionTst/Videos>
Previous to that I was using a method of my own that worked on some, failed on others. Then I stumbled into this "realpath" command, but I can not make it work as I need.
from what I see, "realpath" on the command-line merely prints the actual path from where the command is issued. ie: it does not construct a path similar to ln -- (paka)Patrick Shanahan Plainfield, Indiana, USA @ptilopteri http://en.opensuse.org openSUSE Community Member facebook/ptilopteri Registered Linux User #207535 @ http://linuxcounter.net Photos: http://wahoo.no-ip.org/piwigo paka @ IRCnet freenode -- To unsubscribe, e-mail: opensuse-support+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-support+owner@opensuse.org
On 09/03/2019 16.29, Patrick Shanahan wrote:
* Carlos E. R.
[03-09-19 09:54]: Hi,
I have a scripting problem.
I want to create relative paths. Googling told me I need to use:
realpath --relative-to=something someotherthing
But I can't find the correct concoction.
I have the following structure (TV recordings):
/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/notes /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg
From that list of absolute paths, I want to produce a relative one:
3_MyBook_Videos/Lore.mpeg or ./3_MyBook_Videos/Lore.mpeg ../3_MyBook_Videos/Big Bang/notes ../../3_MyBook_Videos//Big Bang/Season 6/06x01.mpeg
I got a headache, but no working solution.
Example:
cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/" "/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg" ../../../../data/My_Book/Fusion/Videos/Lore.mpeg cer@Isengard:~/FusionTst/Videos>
cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg" "/home/cer/FusionTst/Videos/" ../../../../../home/cer/FusionTst/Videos cer@Isengard:~/FusionTst/Videos>
Previous to that I was using a method of my own that worked on some, failed on others. Then I stumbled into this "realpath" command, but I can not make it work as I need.
from what I see, "realpath" on the command-line merely prints the actual path from where the command is issued. ie: it does not construct a path similar to ln
No... Back to googling. -- Cheers / Saludos, Carlos E. R. (from 15.0 x86_64 at Telcontar)
* Carlos E. R.
On 09/03/2019 16.29, Patrick Shanahan wrote:
* Carlos E. R.
[03-09-19 09:54]: Hi,
I have a scripting problem.
I want to create relative paths. Googling told me I need to use:
realpath --relative-to=something someotherthing
But I can't find the correct concoction.
I have the following structure (TV recordings):
/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/notes /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg
From that list of absolute paths, I want to produce a relative one:
3_MyBook_Videos/Lore.mpeg or ./3_MyBook_Videos/Lore.mpeg ../3_MyBook_Videos/Big Bang/notes ../../3_MyBook_Videos//Big Bang/Season 6/06x01.mpeg
I got a headache, but no working solution.
Example:
cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/" "/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg" ../../../../data/My_Book/Fusion/Videos/Lore.mpeg cer@Isengard:~/FusionTst/Videos>
cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg" "/home/cer/FusionTst/Videos/" ../../../../../home/cer/FusionTst/Videos cer@Isengard:~/FusionTst/Videos>
Previous to that I was using a method of my own that worked on some, failed on others. Then I stumbled into this "realpath" command, but I can not make it work as I need.
from what I see, "realpath" on the command-line merely prints the actual path from where the command is issued. ie: it does not construct a path similar to ln
No...
Back to googling.
-- Cheers / Saludos,
Carlos E. R. (from 15.0 x86_64 at Telcontar)
did you read the man page? -- (paka)Patrick Shanahan Plainfield, Indiana, USA @ptilopteri http://en.opensuse.org openSUSE Community Member facebook/ptilopteri Registered Linux User #207535 @ http://linuxcounter.net Photos: http://wahoo.no-ip.org/piwigo paka @ IRCnet freenode -- To unsubscribe, e-mail: opensuse-support+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-support+owner@opensuse.org
* Carlos E. R.
On 09/03/2019 16.29, Patrick Shanahan wrote:
* Carlos E. R.
[03-09-19 09:54]: Hi,
I have a scripting problem.
I want to create relative paths. Googling told me I need to use:
realpath --relative-to=something someotherthing
But I can't find the correct concoction.
I have the following structure (TV recordings):
/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/notes /home/cer/FusionTst/Videos/3_MyBook_Videos/Big Bang/Season 6/06x01.mpeg
From that list of absolute paths, I want to produce a relative one:
3_MyBook_Videos/Lore.mpeg or ./3_MyBook_Videos/Lore.mpeg ../3_MyBook_Videos/Big Bang/notes ../../3_MyBook_Videos//Big Bang/Season 6/06x01.mpeg
I got a headache, but no working solution.
Example:
cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/" "/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg" ../../../../data/My_Book/Fusion/Videos/Lore.mpeg cer@Isengard:~/FusionTst/Videos>
cer@Isengard:~/FusionTst/Videos> realpath --relative-to="/home/cer/FusionTst/Videos/3_MyBook_Videos/Lore.mpeg" "/home/cer/FusionTst/Videos/" ../../../../../home/cer/FusionTst/Videos cer@Isengard:~/FusionTst/Videos>
Previous to that I was using a method of my own that worked on some, failed on others. Then I stumbled into this "realpath" command, but I can not make it work as I need.
from what I see, "realpath" on the command-line merely prints the actual path from where the command is issued. ie: it does not construct a path similar to ln
No...
Back to googling.
-- Cheers / Saludos,
Carlos E. R. (from 15.0 x86_64 at Telcontar)
have you made it work previously? -- (paka)Patrick Shanahan Plainfield, Indiana, USA @ptilopteri http://en.opensuse.org openSUSE Community Member facebook/ptilopteri Registered Linux User #207535 @ http://linuxcounter.net Photos: http://wahoo.no-ip.org/piwigo paka @ IRCnet freenode -- To unsubscribe, e-mail: opensuse-support+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-support+owner@opensuse.org
On Sat, 9 Mar 2019 15:51:38 +0100
"Carlos E. R."
Hi,
I have a scripting problem.
I want to create relative paths. Googling told me I need to use:
You'll have to explain what you mean more explicitly for me to be able to understand what you want. A more complete description of the use case. -- To unsubscribe, e-mail: opensuse-support+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse-support+owner@opensuse.org
On 09/03/2019 21.24, Dave Howorth wrote:
On Sat, 9 Mar 2019 15:51:38 +0100 "Carlos E. R."
wrote: Hi,
I have a scripting problem.
I want to create relative paths. Googling told me I need to use:
You'll have to explain what you mean more explicitly for me to be able to understand what you want. A more complete description of the use case.
See my recent reply to David T-G and Andrei Borzenkov -- Cheers / Saludos, Carlos E. R. (from 15.0 x86_64 at Telcontar)
participants (7)
-
Andrei Borzenkov
-
Carlos E. R.
-
Dave Howorth
-
David T-G
-
jdd@dodin.org
-
L A Walsh
-
Patrick Shanahan