Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xargs to concatenate extension onto an argument

Tags:

awk

xargs

I am trying to set up a script to automatically delete a .torrent file based on an output from transmission-remote.

transmission-remote http://localhost/transmission -l | grep 100% | grep Finished | awk '{print $10}' | xargs -I% -r -p -n 1 /bin/rm /mnt/samba/Dropbox/%.torrent

Here is my current output:

/bin/rm /mnt/samba/Dropbox/MyTorrent.torrent ?...y

/bin/rm: cannot remove `/mnt/samba/Dropbox/MyTorrent.torrent': No such file or directory

The name that is outputted is identical to the .torrent name

root@mfalc:/mnt/samba/Dropbox/# ls
MyTorrent.torrent
root@mfalc:/mnt/samba/Dropbox/# 

Here is also what it looks like before the awk

root@mfalc:~# transmission-remote http://localhost/transmission -l | grep 100% | grep Finished | grep Done 
  12   100%  174.4 MiB  Done         0.0     0.0   0.01  Finished     MyTorrent

I have obscured the actual torrent name but, does anyone have any suggestions? Am I concatenating the .torrent extension with xargs correctly?

like image 600
yougotborked Avatar asked Feb 02 '26 06:02

yougotborked


1 Answers

Well you don't need xargs for that, awk can do it for you (only that part):

awk '{print $10 ".torrent"}'

Even better awk can call rm on it:

awk '{system("rm -i " $10 ".torrent")}'

If you have space(s) in the torrent names:

awk '{system("rm -i " gensub(" ","\\\\ ","g",$10) ".torrent")}'
like image 155
Zsolt Botykai Avatar answered Feb 04 '26 00:02

Zsolt Botykai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!