Results 1 to 4 of 4
I'm having a hell of a time writing a script in which I would like to obtain two variables from the current directory.
I'm trying to parse the season and ...
- 11-25-2009 #1Just Joined!
- Join Date
- Nov 2008
- Posts
- 8
regexp with sed help
I'm having a hell of a time writing a script in which I would like to obtain two variables from the current directory.
I'm trying to parse the season and episode number from the directory name, ie
"Top Gear 14x01 - blah"
and
"Top Gear 5x08 - blah"
but I can't come up with a common regexp set for sed that will get me the season (14 or 5) and episode (01 or 0
consistently. I either get 4 and 5 or 14 and nothing for the season.
Any help with figuring this out is much appreciated!
thanks!
- 11-25-2009 #2Linux User
- Join Date
- Aug 2006
- Posts
- 458
you can do it with the shell
Code:$ file="Top Gear 14x01 - blah" $ set -- $file $ echo $3 14x01 $ t=$3 $ IFS="x" $ set -- $t $ echo $1 14 $ echo $2 01 $ unset IFS
- 11-26-2009 #3
How about this?
Code:#!/bin/bash DIR="Top Gear 5x08 - blah" SEASON="$(echo "$DIR" | sed 's/.* \([0-9]\+\)x[0-9]\+ .*/\1/')" EPISODE="$(echo "$DIR" | sed 's/.* [0-9]\+x\([0-9]\+\) .*/\1/')"
- 11-26-2009 #4Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
It would be even easier if you use perl:
Code:$ echo "Top Gear 5x08 - bla"| perl -e 'while (<>) {next if !/(\d+)x(\d+)/; print("season=$1;episode=$2\n");}'


Reply With Quote