0

I am writing a bash script where i want to use the grep output below "06" in a link i'm creating.

echo [super-shows]Super.Show.S06.1080p.BluRay.DD-EX.5.1.x264 | grep -oP '(?<='S')\d{2}(?=\.)'

ln -s /home/Download/[super-shows]Super.Show.S06.1080p.BluRay.DD-EX.5.1.x264 /home/Media/TV/Super.Show/**06**
angelsen
  • 35
  • 5

1 Answers1

1

It's easy with using xargs, propably that is allready installed, if not I'm sure it's available in the package manager for every distribution.

echo "[super-shows]Super.Show.S06.1080p.BluRay.DD-EX.5.1.x264" | grep -oP '(?<='S')\d{2}(?=\.)' | xargs -I{} ln -s /home/Download/[super-shows]Super.Show.S06.1080p.BluRay.DD-EX.5.1.x264 /home/Media/TV/Super.Show/**{}**
zabeltech
  • 963
  • 11
  • 27
  • Thanks! Works great! If i wanted to use grep to echo Super.Show how could i change the regexp to do so? – angelsen Nov 20 '16 at 20:05
  • 1
    @angelsen ```echo "[super-shows]Super.Show.S06.1080p.BluRay.DD-EX.5.1.x264" | grep -oP '(?<=']').*\d{2}(?=\.)'``` for example would output ```Super.Show.S06``` you can easily play around with it to fit your needs – zabeltech Nov 20 '16 at 20:19
  • Figures! I am also able to make directories using grep and xargs, how could i make directory **within** the made directory based of grep output? e.g. /home/Media/TV/Super.Show/06/BluRay – angelsen Nov 20 '16 at 20:45
  • 1
    Eureka! Ended up using parallel. `echo "[super-shows]Super.Show.S06.1080p.BluRay.DD-EX.5.1.x264" | grep -oP (?<='-')\w*(?=\.)' | parallel -N2 mkdir -p /home/Download/{1}/{2}` – angelsen Nov 21 '16 at 11:58