I'm so relieved to be back at my keyboard, with a roof over my head, fridge full of food, and plentiful water of varied temperature. I was feeling kind of stuck because I had a repository that I had downloaded that didn't have the proper credentials, and it was preventing updating. I got that all cleared away, so now I have:
$ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 20.04.2 LTS Release: 20.04 Codename: focal $
One of the first things I'll do is create a webpage describing the trip, and that is going to require that a bunch of odd images gets herded to the net, with an exact number of corresponding captions. For this task, I find that I can really economize on GUI events with perl and a little skill on the command line.
But I'm one of those guys who would make every mistake in the book if I started at square one. I know that I had a thread some time back called renaming all files in a directory. I tried to search for this with keywords but had to resort to scrolling through my writeups back to 2012. I was gonna complain that the search didn't work. However, I had searched for the word 'rename' not 'renaming', and I realize that the problem is not with the software.
I tried one of the answers I hadn't used before:
ls | perl -nle 'BEGIN {$counter=0}; $old=$_;$new="image"."$counter"." +.jpg"; +rename($old,$new);$counter++;' $
That command didn't work at first, but I could get my way to one that did because what exists between single quotations is lexical perl that I understand. And gosh, I've been pretty diligent about studying this including taking in Util's talk at 2020 perl conference, which helped me understand how people "get there on the command line."
$ ls | perl -nle 'BEGIN {$counter=0}; $old=$_;$new="image"."$counter". +"jpg"; > +rename($old,$new);$counter++;' $ ls | perl -nle 'BEGIN {$counter=0}; $old=$_;$new="image"."$counter". +".jpg"; +rename($old,$new);$counter++;' $
and voila...
$ pwd /home/hogan/6.scripts.personal/1.umatilla.1./template_stuff/aimages $ ls image0.jpg image12.jpg image15.jpg image3.jpg image6.jpg image9. +jpg image10.jpg image13.jpg image1.jpg image4.jpg image7.jpg image11.jpg image14.jpg image2.jpg image5.jpg image8.jpg $
Another modification gets my captions looking all uniform, so I know I've got a bijection going:
ls | perl -nle 'BEGIN {$counter=0}; $old=$_;$new="caption"."$counter". +".txt"; +rename($old,$new);$counter++;'
$ pwd /home/hogan/6.scripts.personal/1.umatilla.1./template_stuff/captions $ ls caption0.txt caption13.txt caption2.txt caption6.txt caption10.txt caption14.txt caption3.txt caption7.txt caption11.txt caption15.txt caption4.txt caption8.txt caption12.txt caption1.txt caption5.txt caption9.txt $
Now I know that my data will be well-conditioned for use by other scripts to get it onto the net.
This was just my day in having perl making something easier....
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Renaming all files in a directory
by eyepopslikeamosquito (Archbishop) on Feb 02, 2021 at 05:27 UTC | |
by Fletch (Bishop) on Feb 02, 2021 at 05:43 UTC | |
Re: Renaming all files in a directory
by jwkrahn (Abbot) on Feb 02, 2021 at 04:32 UTC | |
by Anonymous Monk on Feb 02, 2021 at 12:46 UTC | |
by Cristoforo (Curate) on Feb 02, 2021 at 16:57 UTC | |
Re: Renaming all files in a directory
by choroba (Cardinal) on Feb 02, 2021 at 13:19 UTC | |
Re: Renaming all files in a directory -- perl -n -p and empty files oneliner
by Discipulus (Canon) on Feb 02, 2021 at 11:35 UTC | |
by choroba (Cardinal) on Feb 02, 2021 at 13:44 UTC | |
A reply falls below the community's threshold of quality. You may see it by logging in. |