0

with for example sed, awk or python.

there will be 548 lines in the original txt file

from this:

    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

to this:

    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
1
  • 1
    Maybe awk '{x=sprintf("%04d",++n); gsub("0001",x);print}' Commented Feb 25, 2016 at 22:48

3 Answers 3

0

This should work assuming the prefixes used in the last two fields (sn in your example snippet) are derived from the third field from the end:

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
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

enter image description here

0

It'd be easier to just regenerate the file, assuming that the sequence continues from 1 to 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .