0

このwhileループを使用して、いくつかの行を別の形式に変更する必要があります。

while IFS= read -r line; 
do 
var=$(echo "$line" | grep -oE "http://img[0-9].domain.xy/t/[0-9][0-9][0-9]/[0-9][0-9][0-9]/" | uniq);
echo "$line" | sed -e 's|http://img[0-9].domain.xy/t/[0-9][0-9][0-9]/[0-9][0-9][0-9]/||g' -e "s|.*|&"${var}"|g" >> newFile; 
done < file;

この形式を変更する

<iframe  src="http://domain.xy/load.php?file=2259929" frameborder="0" scrolling="no"></iframe>|http://img9.domain.xy/t/929/320/1_2259929.jpg;http://img9.domain.xy/t/929/320/2_2259929.jpg;http://img9.domain.xy/t/929/320/3_2259929.jpg;http://img9.domain.xy/t/929/320/4_2259929.jpg;http://img9.domain.xy/t/929/320/5_2259929.jpg;http://img9.domain.xy/t/929/320/6_2259929.jpg;http://img9.domain.xy/t/929/320/7_2259929.jpg;http://img9.domain.xy/t/929/320/8_2259929.jpg;http://img9.domain.xy/t/929/320/9_2259929.jpg;http://img9.domain.xy/t/929/320/10_2259929.jpg|13m5s

そして私にその出力を与えます。

 <iframe  src="http://domain.xy/load.php?file=2259929" frameborder="0" scrolling="no"></iframe>|1_2259929.jpg;2_2259929.jpg;3_2259929.jpg;4_2259929.jpg;5_2259929.jpg;6_2259929.jpg;7_2259929.jpg;8_2259929.jpg;9_2259929.jpg;10_2259929.jpg|13m5s|http://img9.domain.xy/t/929/320/

それはすべて正しく動作します!!!

しかし、変更したい時間の値もあります。13 分 5 秒から 00:13:5 まで、またはそれ以上 13 分 5 秒から 00:13:05

ループの最後で別の grep + sed コマンドを使用しようとしています。

while IFS= read -r line; 
do 
var=$(echo "$line" | grep -oE "http://img[0-9].domain.xy/t/[0-9][0-9][0-9]/[0-9][0-9][0-9]/" | uniq);
echo "$line" | sed -e 's|http://img[0-9].domain.xy/t/[0-9][0-9][0-9]/[0-9][0-9][0-9]/||g' -e "s|.*|&"${var}"|g" >> newFile; 
done < file;
grep -oE "[0-9]*m[0-9]*[0-9]s" newFile | sed -e 's|^|00:|' -e s'|m|:|' -e s'|s||'

これにより、完全な行ではなく、数値の出力のみが得られます。

00:13:5
00:3:18
00:1:50

等々

完全な行を取得して、 13m5s を 00:13:5 に変更するにはどうすればよいですか?

while ループの後に grep を使用せずに sed を使用すると、間違った文字が変更されます。そして、各行の先頭に 00: を置きます。

それを処理する最良の方法は何ですか。コマンドを既存のループに統合するのが最善だと思います。しかし、私は結果なしで多くの異なるバリエーションを試しました。

助けてくれてthx

どうも

4

2 に答える 2

1

何が起こっているのかを簡単に理解できるように、コードをいくつかの追加部分に分割しました。私が正しいと信じている結果は次のとおりです。

# Read each field in to separate variables
while IFS='|' read iframe urls time; do
        # Get the first URL from the ';'-separated list
        url="${urls%%;*}"
        # Get the base URL by matching up to the last '/' (and add it back since the match is exclusive)
        base_url="${url%/*}"'/'

        # Remove the base URL from the list of full URLs so only the filenames are left
        files="${urls//$base_url/}"

        # Parse the minute and second out from the '##m#s' string
        IFS='ms' read min sec <<<"$time"

        # Print the new line - note the numeric formatting in the third column
        printf '%s|%s|00:%02d:%02d|%s\n' "$iframe" "$files" "$min" "$sec" "$base_url"
done <file

13m5sに提出する方法に関する特定の要求に答える行00:13:05は、次の 2 つです。

IFS='ms' read min sec <<<"$time"

printf '%s|%s|00:%02d:%02d|%s\n' "$iframe" "$files" "$min" "$sec" "$base_url"

このread行はIFS、文字を分割するように指示しmたりs、分と秒の変数を簡単に読み取れるようにするために使用します。

withのprintf行は、変数と変数をゼロで埋められた 2 桁の数字として00:%02d:%02dフォーマットします。$min$sec

于 2013-10-05T02:40:08.127 に答える
1

grep式に一致する行のみを出力します。sed の組み込み行マッチングを使用して、置換を特定の行に制限します。

sed '/[0-9]*m[0-9]*[0-9]s/{s|^|00:|;s|m|:|;s'|s||;}'

または多分これ:

sed 's/\([0-9]*\)m\([0-9]*[0-9]\)s/00:\1:\2/'
于 2013-10-05T01:45:21.997 に答える