Aumenta o inteiro na string em 1 para cada linha

0

por exemplo, sed, awk ou python.

haverá 548 linhas no arquivo txt original

disso:

    http://twit.cachefly.net/audio/sn/sn0001/sn0001.mp3
    http://twit.cachefly.net/audio/sn/sn0001/sn0001.mp3
    http://twit.cachefly.net/audio/sn/sn0001/sn0001.mp3

para isso:

    http://twit.cachefly.net/audio/sn/sn0001/sn0001.mp3
    http://twit.cachefly.net/audio/sn/sn0002/sn0002.mp3
    http://twit.cachefly.net/audio/sn/sn0003/sn0003.mp3
    
por user35538 25.02.2016 / 21:42

3 respostas

0

Isso deve funcionar presumindo que os prefixos usados nos dois últimos campos ( sn em seu snippet de exemplo) sejam derivados do terceiro campo do final:

awk -vOFS='/' -F'/' '{$(NF-1)=sprintf("%s%04d", $(NF-2), FNR);
      $NF=$(NF-1)".mp3"; print}' file
http://twit.cachefly.net/audio/sn/sn0001/sn0001.mp3
http://twit.cachefly.net/audio/sn/sn0002/sn0002.mp3
http://twit.cachefly.net/audio/sn/sn0003/sn0003.mp3
http://twit.cachefly.net/audio/sn/sn0004/sn0004.mp3
http://twit.cachefly.net/audio/sn/sn0005/sn0005.mp3
http://twit.cachefly.net/audio/sn/sn0006/sn0006.mp3
http://twit.cachefly.net/audio/sn/sn0007/sn0007.mp3
http://twit.cachefly.net/audio/sn/sn0008/sn0008.mp3
http://twit.cachefly.net/audio/sn/sn0009/sn0009.mp3
http://twit.cachefly.net/audio/sn/sn0010/sn0010.mp3
http://twit.cachefly.net/audio/sn/sn0011/sn0011.mp3
http://twit.cachefly.net/audio/sn/sn0012/sn0012.mp3
http://twit.cachefly.net/audio/sn/sn0013/sn0013.mp3
http://twit.cachefly.net/audio/sn/sn0014/sn0014.mp3
http://twit.cachefly.net/audio/sn/sn0015/sn0015.mp3
http://twit.cachefly.net/audio/sn/sn0016/sn0016.mp3
http://twit.cachefly.net/audio/sn/sn0017/sn0017.mp3
http://twit.cachefly.net/audio/sn/sn0018/sn0018.mp3
http://twit.cachefly.net/audio/sn/sn0019/sn0019.mp3
http://twit.cachefly.net/audio/sn/sn0020/sn0020.mp3
http://twit.cachefly.net/audio/sn/sn0021/sn0021.mp3
http://twit.cachefly.net/audio/sn/sn0022/sn0022.mp3
http://twit.cachefly.net/audio/sn/sn0023/sn0023.mp3
http://twit.cachefly.net/audio/sn/sn0024/sn0024.mp3
http://twit.cachefly.net/audio/sn/sn0025/sn0025.mp3
http://twit.cachefly.net/audio/sn/sn0026/sn0026.mp3
http://twit.cachefly.net/audio/sn/sn0027/sn0027.mp3
http://twit.cachefly.net/audio/sn/sn0028/sn0028.mp3
http://twit.cachefly.net/audio/sn/sn0029/sn0029.mp3
http://twit.cachefly.net/audio/sn/sn0030/sn0030.mp3
http://twit.cachefly.net/audio/sn/sn0031/sn0031.mp3
http://twit.cachefly.net/audio/sn/sn0032/sn0032.mp3
http://twit.cachefly.net/audio/sn/sn0033/sn0033.mp3
http://twit.cachefly.net/audio/sn/sn0034/sn0034.mp3
http://twit.cachefly.net/audio/sn/sn0035/sn0035.mp3
http://twit.cachefly.net/audio/sn/sn0036/sn0036.mp3
http://twit.cachefly.net/audio/sn/sn0037/sn0037.mp3
    
por 25.02.2016 / 21:55
0
#!/bin/bash
echo "Enter File you want to read"
read file
i=0;

if [ -f $file ]
then
      echo "file is avalible"
      while  read -r  line
      do
              echo "$line" | sed "s/http:\/\/twit.cachefly.net\/audio\/sn\/sn0001\/sn0001.mp3/http:\/\/twit.cachefly.net\/audio\/    sn\/sn000$i\/sn000$i.mp3/g"

      ((i++))

      done<$file





else
      echo "file is not abalible"
fi

    
por 25.02.2016 / 22:24
0

Seria mais fácil apenas regenerar o arquivo, assumindo que a sequência continua de 1 a 548:

$ cat regen.sh
#!/bin/bash

for i in $(seq -w 1 548); do
     echo "http://twit.cachefly.net/audio/sn/sn0${i}/sn0{$i}.mp3"
done

$ bash regen.sh > newfile

$ cat netFile
http://twit.cachefly.net/audio/sn/sn0001/sn0001.mp3
http://twit.cachefly.net/audio/sn/sn0002/sn0002.mp3
http://twit.cachefly.net/audio/sn/sn0003/sn0003.mp3
http://twit.cachefly.net/audio/sn/sn0004/sn0004.mp3
...
http://twit.cachefly.net/audio/sn/sn0548/sn0548.mp3
    
por 25.02.2016 / 23:41