在多线S $ P $垫'sed的'命令 [英] Spread 'sed' command over multiple lines

查看:132
本文介绍了在多线S $ P $垫'sed的'命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在几个线在bash文件试图为s $ P $垫1 sed命令。我有检查的sed的多模式,我希望通过线路的变化,以分离出一些图案。这是我不工作,把一切在同一行当前脚本的作品,但我希望只是清理了一下,分裂的事情了。

I am trying to spread one sed command over several lines in a bash file. I have multiple patterns that sed checks for and I am hoping to separate some of the patterns by a line change. Here is my current script that does not work, putting everything on one line works but I was hoping to just clean it up a bit and split things up.

#!/bin/sh -f

#files=$(ls -1 | egrep '.avi|.mkv');

#echo $files
for f in *.mkv *.avi;
 do
  renF=`echo $f | tr '.' ' ' | sed -e 's/ \([^ ]*\)$/.\1/; s/\ \[sharethefiles\ com\]//i' \
  -e 's/\ x264\-Ctu//i; s/\ x264\-Bia//i; s/\ x264\-Fov//i' \
  -e 's/\ Xvid\-Lol//i; s/\ Xvid\-Xor//i; s/\ Xvid\-Notv//i; s/\ Xvid\-Fqm//i; s/\ Xvid\-p0w4//i; Xvid\-BIA//i; s/\ Xvid\-Chgrp//i; s/\ Xvid\-Fov//i' \
  -e 's/\ PDTV\-Fov//i; s/\ PDTV\-River//i; s/\ PDTV\-Sfm' \
  -e 's/\ Dts\-Chd//i; s/\ WEB\-DL//i; s/\ H264\-SURFER//i' \
  -e 's/\ Dsr//; s/\ WS//i; s/\ PDTV//i; s/\ X264//i; s/\ Blu\-Ray//; s/\ Bdrip//i; s/\ Bluray//i; s/\ HDTV//i; s/\ DTS//i; s/\ AC3//i; s/\ Dd5//i; s/\ Dualaudio//i; s/\ AAC2//i; s/\ XVID//i'`
  #echo $renF
  if [ "$f" == "$renF" ]; then
        echo "FileName already cleaned."
  else
        mv "$f" "$renF"
  fi
 done

感谢您的帮助!

推荐答案

现在的问题是在这条线:

The problem is on this line:

-e 's/\ Xvid\-Lol//i; s/\ Xvid\-Xor//i; s/\ Xvid\-Notv//i; s/\ Xvid\-Fqm//i; s/\ Xvid\-p0w4//i; Xvid\-BIA//i; s/\ Xvid\-Chgrp//i; s/\ Xvid\-Fov//i' \

有一个失踪 S / 。它应该是:

There's a missing s/. It should be:

-e 's/\ Xvid\-Lol//i; s/\ Xvid\-Xor//i; s/\ Xvid\-Notv//i; s/\ Xvid\-Fqm//i; s/\ Xvid\-p0w4//i; s/\ Xvid\-BIA//i; s/\ Xvid\-Chgrp//i; s/\ Xvid\-Fov//i' \

我包括一致性反斜线。

I included the backslash for consistency.

此行​​缺少 //我

-e 's/\ PDTV\-Fov//i; s/\ PDTV\-River//i; s/\ PDTV\-Sfm

修正:

-e 's/\ PDTV\-Fov//i; s/\ PDTV\-River//i; s/\ PDTV\-Sfm//i

错误消息我是什么导致我的错误来源:

The error messages I got were what led me to the source of the errors:

sed: -e expression #3, char 93: unknown command: `X'

sed: -e expression #4, char 51: unterminated `s' command

下面是关于如何使一个建议这更可读性和可维护性:

Here's a suggestion on how to make this more readable and maintainable:

while read -r pattern
do
    sedscript+="$pattern;"
done <<EOF
s/ \([^ ]*\)$/.\1/
s/\ \[sharethefiles\ com\]//i
s/\ x264\-Ctu//i
s/\ x264\-Bia//i
...
s/\ XVID//i
EOF

renF=$(echo $f | tr '.' ' ' | sed -e "$sedscript")

这篇关于在多线S $ P $垫'sed的'命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆