1
echo "super-super.show.s01.e01" | grep -oPi '(?<=-)[\w\W]+(?=\.s\d\d)|s\d\d|e\d\d' | parallel -N3 ln -sf ~/super-super.show.s01.e01 ~/TV/{1}/{2}/{3}
# tries to make ~/TV/super.show/s01/e01 failes due to no such file or directory

How can i write my code so it creates the needed dir?

if there is no e01 in the string it tries to create link to:

~/TV/super.show/s01/{3}

How can i write my code so it then creates link to:

~/TV/super.show/s01
angelsen
  • 35
  • 5
  • 1
    Do you really need `parallel` to create symlinks? If you rewrite your code into something readable using a `while` loop, then you can simply use `mkdir -p`. – Kijewski Nov 22 '16 at 00:07
  • Well im not quite sure. I want to create links where i use the output of `grep` to create the subdirectory to the links and i managed to do that with `parallel`. Can this be done easier? – angelsen Nov 22 '16 at 00:14
  • @mklement0 I've tried with `xargs -i{}`, but then i only get the `{}` variable to us for several outputs from `grep`... as far as i know. – angelsen Nov 22 '16 at 00:37
  • 1
    `xargs` will f.ck you over if you use names like '>>super<< 12" star*show.s01.e01'. GNU Parallel will not. – Ole Tange Nov 22 '16 at 00:41

1 Answers1

1

Maybe:

echo '>>super<< 12" star*show.s01.e01.mp4' |
  parallel --rpl '{dir} s:\.(s\d\d):/$1:; s:\.(e\d\d):/$1:; s/\....$//;' mkdir -p ~/TV/{dir}';' ln -s {} ~/TV/{dir}
Ole Tange
  • 31,768
  • 5
  • 86
  • 104
  • Guess I'll have to do it this way hoped i could do all i wanted in one line. – angelsen Nov 22 '16 at 00:34
  • 1
    Nicely done. GNU `parallel` calls this method of modifying the input a [Perl expression replacement string](https://www.gnu.org/software/parallel/parallel_tutorial.html#Replacement-strings). – mklement0 Nov 22 '16 at 13:19