Editing file with shell script links

Asked

Viewed 69 times

0

I have a file with 130 links to download via wget, all files are with the listed links such as:

http://minhateca.com.br/Animesdojonny/Desenhos/THUNDERCATS/Thundercats+-+Completo/Thundercats-EP001,743727846.rar
http://minhateca.com.br/Animesdojonny/Desenhos/THUNDERCATS/Thundercats+-+Completo/Thundercats-EP002,743718235.rar
http://minhateca.com.br/Animesdojonny/Desenhos/THUNDERCATS/Thundercats+-+Completo/Thundercats-EP003,743703720.rar

however I have to edit the file in which these links are and leave them so:

#Thundercats-EP001.rar
#http://minhateca.com.br/Animesdojonny/Desenhos/THUNDERCATS/Thundercats+-+Completo/Thundercats-EP001,743727846.rar
wget -O Thundercats-EP001.rar "http://s8580.minhateca.com.br/File.aspx?e=B80c6ks-HZZR2HnE2P_Qj0fY-7MZkLDpI14Qrtckc2t05nqVSDeWdt9kcRhuVHjt_FcwOfwZWuehkAwz613_Df_nzlazlznNiZD2vqM-PO0ST7b3hOVRZD_8WmGTRL3OKB3FEbcAqy5_olQ5syvbgA&pv=2"
unrar e Thundercats-EP001.rar


#Thundercats-EP002.rar
#http://minhateca.com.br/Animesdojonny/Desenhos/THUNDERCATS/Thundercats+-+Completo/Thundercats-EP002,743718235.rar
wget -O Thundercats-EP002.rar "http://s8562.minhateca.com.br/File.aspx?e=aoEnt8uY-4ccqVF8bEQ7dbdJcsgPlkKl8zLQUXjU-WZzX-PJlAOxeNOvuRDm-9MNxnRB3_9psA36wqfRAycHXgldFGoxz_xaENafIQ6t_yhtWLYgyeh-5nHQdyht6tFxb-mOJBFXvaBfgu5L0zK12A&pv=2"
unrar e Thundercats-EP002.rar


#Thundercats-EP003.rar
#http://minhateca.com.br/Animesdojonny/Desenhos/THUNDERCATS/Thundercats+-+Completo/Thundercats-EP003,743703720.rar
wget -O Thundercats-EP003.rar "http://s8581.minhateca.com.br/File.aspx?e=K218wb9_yo9qMQ9KU174NRrct9sJ_Kg-Y27HmaoOGAmCsFRDMzz0GnAu8zso-EzVYxKTYM2w1Fh7-m1eyCmFzf2RWQzzdc4ZguCKj72cV0xt3RxggUicqrUotOBzbxr5P4EXUpsPSdgT6lhkL1XmbA&pv=2"
unrar e Thundercats-EP003.rar

then I made a program that edits it but instead of enumerating it then it is editing it as follows:

#Thundercats-EP001.rar
#http://minhateca.com.br/Animesdojonny/Desenhos/THUNDERCATS/Thundercats+-+Completo/Thundercats-EP001,743727846.rar
wget -O Thundercats-EP001.rar ""
unrar e Thundercats-EP001.rar


#Thundercats-EP001.rar
#http://minhateca.com.br/Animesdojonny/Desenhos/THUNDERCATS/Thundercats+-+Completo/Thundercats-EP002,743718235.rar
wget -O Thundercats-EP001.rar ""
unrar e Thundercats-EP001.rar


#Thundercats-EP001.rar
#http://minhateca.com.br/Animesdojonny/Desenhos/THUNDERCATS/Thundercats+-+Completo/Thundercats-EP003,743703720.rar
wget -O Thundercats-EP001.rar ""
unrar e Thundercats-EP001.rar

when you should edit like this:

#Thundercats-EP001.rar
#http://minhateca.com.br/Animesdojonny/Desenhos/THUNDERCATS/Thundercats+-+Completo/Thundercats-EP001,743727846.rar
wget -O Thundercats-EP001.rar ""
unrar e Thundercats-EP001.rar


#Thundercats-EP002.rar
#http://minhateca.com.br/Animesdojonny/Desenhos/THUNDERCATS/Thundercats+-+Completo/Thundercats-EP002,743718235.rar
wget -O Thundercats-EP002.rar ""
unrar e Thundercats-EP002.rar


#Thundercats-EP003.rar
#http://minhateca.com.br/Animesdojonny/Desenhos/THUNDERCATS/Thundercats+-+Completo/Thundercats-EP003,743703720.rar
wget -O Thundercats-EP003.rar ""
unrar e Thundercats-EP003.rar

the program is this below:

#!/bin/bash

LOCATES=${LOCATES:-$(find . -name "downloads")}

ALL_NAMES=${ALL_NAMES:-$(cat ${LOCATES} | cut -f8 -d /)}
ALL_LINKS=${ALL_LINKS:-$(cat ${LOCATES})}

VEC_NAMES=(${ALL_NAMES})
VEC_LINKS=(${ALL_LINKS})

echo ""
for ((l = 1; l <= ${#VEC_NAMES[@]}; l++))
do
NAMES=$(printf "%s%03u.%s" "${ALL_NAMES:0:14}" ${l} "${ALL_NAMES:28:3}")

sed -i 's/^/#'${NAMES}'\n#/g;s/$/\nwget -O '${NAMES}' '\"\"'\nunrar e '${NAMES}'\n\n/g;' ${LOCATES}

done #fim primeiro for

what is my mistake?

  • 1

    awk 'BEGIN { FS="/" } { split($8, a, ","); printf "#%s.rar\n#%s\nwget -O %s.rar \"%s\"\nunrar -e %s.rar\n\n", a[1], $0, a[1], $0, a[1] }' < arquivo.txt

  • this command worked out thanks to the help...

1 answer

1


a simpler way would be:

awk  -i inplace -F "[/,]"  '{print 
 $8".rar"}' links.txt

cat links.txt

Thundercats-EP001.rar

Thundercats-EP002.rar.

Thundercats-EP003.rar

Browser other questions tagged

You are not signed in. Login or sign up in order to post.