How can I rename files with names like Stargate SG-1 Season 01 Episode 01 to just "s01e01"? Of course, variable numbering. I already have something like this:
Stargate SG-1 Season 01 Episode 01
for file in *.mkv; do mv "$file" "$(echo "$file" | sed -e "REGEX HERE")
I just need a sed command that does what I need.
thanks
There is no need for sed, try the following:
#!/bin/bash for f in *.mkv; do set -- $f mv "$f" s${4}e${6} done
In action:
$ ls Stargate SG-1 Season 01 Episode 01.mkv $ ./l.sh $ ls s01e01.mkv
for file in *.mkv; do mv "$file" "$(echo "$file" | sed -e 's/.*\(\S\+\)\s\+\S\+\s\(\S\+\)$/s\1e\2/')
Awk is also good for this
for file in *.mkv; do mv "$file" $(awk '{print "s", $4, "e", $6}' <<<$file).mkv done
I think this is not a problem for sed :)
I would go this way to rename all * .mkv files:
ls *.mkv | awk '{print "mv \"" $0 "\" s" $4 "e" $6}' | sh
or
ls *.mkv | awk '{print "\"" $0 "\" s" $4 "e" $6}' | xargs mv
Source: https://habr.com/ru/post/1486509/More articles:how to check if a person matches another in twitter API V1.1 - twitterRemove blank lines from text file - filesplicer passing arguments - titaniumC # Application Calling C ++ Method, error: PInvoke: cannot return options - c ++How to pass MyClass [] [] to MyClass **? - c ++solr dataimport from mysql dies when deleting mysql query limit - mysqlFind a point further from other points - algorithmWhy does insert / delete on one array also modify another? - arraysTwo-parameter array sorting - cChange credentials for Push in Git - gitAll Articles