[opensuse] bash script needed to rename a series of files
I have erred and need help to correct. I need to rename a series of files baseed on another series of files which contain 12 matching characters: to be renamed: dse_7905.nef.xmp dse_7906.nef.xmp dse_7907.nef.xmp dse_7908.nef.xmp dse_7910.nef.xmp dse_7915.nef.xmp dse_7916.nef.xmp dse_7917.nef.xmp dse_7919.nef.xmp dse_7920.nef.xmp names to be matched: 190921_094704_dse_7905.nef 190921_094704_dse_7906.nef 190921_094713_dse_7907.nef 190921_094717_dse_7908.nef 190921_094805_dse_7910.nef 190921_094831_dse_7915.nef 190921_094834_dse_7916.nef 190921_094834_dse_7917.nef 190921_094836_dse_7919.nef 190921_094843_dse_7920.nef so I end up with: 190921_094704_dse_7905.nef 190921_094704_dse_7905.nef.xmp 190921_094704_dse_7906.nef 190921_094704_dse_7906.nef.xmp 190921_094713_dse_7907.nef 190921_094713_dse_7907.nef.xmp 190921_094717_dse_7908.nef 190921_094717_dse_7908.nef.xmp 190921_094805_dse_7910.nef 190921_094805_dse_7910.nef.xmp 190921_094831_dse_7915.nef 190921_094831_dse_7915.nef.xmp 190921_094834_dse_7916.nef 190921_094834_dse_7916.nef.xmp 190921_094834_dse_7917.nef 190921_094834_dse_7917.nef.xmp 190921_094836_dse_7919.nef 190921_094836_dse_7919.nef.xmp 190921_094843_dse_7920.nef 190921_094843_dse_7920.nef.xmp tks much, -- (paka)Patrick Shanahan Plainfield, Indiana, USA @ptilopteri http://en.opensuse.org openSUSE Community Member facebook/ptilopteri Photos: http://wahoo.no-ip.org/piwigo paka @ IRCnet freenode -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
Patrick Shanahan wrote:
I have erred and need help to correct. I need to rename a series of files baseed on another series of files which contain 12 matching characters:
Might this do the trick: for i in 190921*09*79*.nef do pref=$(echo $i | cut -d_ -f1-2) suff=$(echo $i | cut -d_ -f3-99) echo mv $suff.xmp ${pref}_${suff}.xmp done If you're happy with the 'mv's, remove echo or pipe into 'sh'. -- Per Jessen, Zürich (16.2°C) http://www.dns24.ch/ - free dynamic DNS, made in Switzerland. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
* Per Jessen <per@computer.org> [09-22-19 04:47]:
Patrick Shanahan wrote:
I have erred and need help to correct. I need to rename a series of files baseed on another series of files which contain 12 matching characters:
Might this do the trick:
for i in 190921*09*79*.nef do pref=$(echo $i | cut -d_ -f1-2) suff=$(echo $i | cut -d_ -f3-99)
echo mv $suff.xmp ${pref}_${suff}.xmp done
If you're happy with the 'mv's, remove echo or pipe into 'sh'.
thanks, exactly what I needed. "cut" was what I was hunting for. I have seldom had the need to employe it and it did not come to this old mind. I was trying to work with filename attributes. much thanks, -- (paka)Patrick Shanahan Plainfield, Indiana, USA @ptilopteri http://en.opensuse.org openSUSE Community Member facebook/ptilopteri Photos: http://wahoo.no-ip.org/piwigo paka @ IRCnet freenode -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
Patrick Shanahan wrote:
* Per Jessen <per@computer.org> [09-22-19 04:47]:
Patrick Shanahan wrote:
I have erred and need help to correct. I need to rename a series of files baseed on another series of files which contain 12 matching characters:
Might this do the trick:
for i in 190921*09*79*.nef do pref=$(echo $i | cut -d_ -f1-2) suff=$(echo $i | cut -d_ -f3-99)
echo mv $suff.xmp ${pref}_${suff}.xmp done
If you're happy with the 'mv's, remove echo or pipe into 'sh'.
thanks, exactly what I needed. "cut" was what I was hunting for. I have seldom had the need to employe it and it did not come to this old mind. I was trying to work with filename attributes.
It could also have been done with bash regex, string matching and extraction, but I'm always a bit a hazy with those - cut does it for me :-) Nice little brainteaser on a Sunday morning. -- Per Jessen, Zürich (19.5°C) http://www.dns24.ch/ - free dynamic DNS, made in Switzerland. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 22/09/2019 04.12, Patrick Shanahan wrote:
I have erred and need help to correct. I need to rename a series of files baseed on another series of files which contain 12 matching characters:
Did you try with krename? It is very powerful. There are recipes on google, too (with krename) on how to do what
to be renamed: dse_7905.nef.xmp dse_7906.nef.xmp dse_7907.nef.xmp dse_7908.nef.xmp dse_7910.nef.xmp dse_7915.nef.xmp dse_7916.nef.xmp dse_7917.nef.xmp dse_7919.nef.xmp dse_7920.nef.xmp
names to be matched: 190921_094704_dse_7905.nef 190921_094704_dse_7906.nef 190921_094713_dse_7907.nef 190921_094717_dse_7908.nef 190921_094805_dse_7910.nef 190921_094831_dse_7915.nef 190921_094834_dse_7916.nef 190921_094834_dse_7917.nef 190921_094836_dse_7919.nef 190921_094843_dse_7920.nef
so I end up with: 190921_094704_dse_7905.nef 190921_094704_dse_7905.nef.xmp 190921_094704_dse_7906.nef 190921_094704_dse_7906.nef.xmp 190921_094713_dse_7907.nef 190921_094713_dse_7907.nef.xmp 190921_094717_dse_7908.nef 190921_094717_dse_7908.nef.xmp 190921_094805_dse_7910.nef 190921_094805_dse_7910.nef.xmp 190921_094831_dse_7915.nef 190921_094831_dse_7915.nef.xmp 190921_094834_dse_7916.nef 190921_094834_dse_7916.nef.xmp 190921_094834_dse_7917.nef 190921_094834_dse_7917.nef.xmp 190921_094836_dse_7919.nef 190921_094836_dse_7919.nef.xmp 190921_094843_dse_7920.nef 190921_094843_dse_7920.nef.xmp
I'm confused about what has to be converted to what. :-? -- Cheers / Saludos, Carlos E. R. (from 15.0 x86_64 at Telcontar)
* Carlos E.R. <robin.listas@gmx.es> [09-22-19 07:11]:
On 22/09/2019 04.12, Patrick Shanahan wrote:
I have erred and need help to correct. I need to rename a series of files baseed on another series of files which contain 12 matching characters:
Did you try with krename? It is very powerful. There are recipes on google, too (with krename) on how to do what
yes, but google for krename recipies didn't occur
to be renamed: dse_7905.nef.xmp dse_7906.nef.xmp dse_7907.nef.xmp dse_7908.nef.xmp dse_7910.nef.xmp dse_7915.nef.xmp dse_7916.nef.xmp dse_7917.nef.xmp dse_7919.nef.xmp dse_7920.nef.xmp
names to be matched: 190921_094704_dse_7905.nef 190921_094704_dse_7906.nef 190921_094713_dse_7907.nef 190921_094717_dse_7908.nef 190921_094805_dse_7910.nef 190921_094831_dse_7915.nef 190921_094834_dse_7916.nef 190921_094834_dse_7917.nef 190921_094836_dse_7919.nef 190921_094843_dse_7920.nef
so I end up with: 190921_094704_dse_7905.nef 190921_094704_dse_7905.nef.xmp 190921_094704_dse_7906.nef 190921_094704_dse_7906.nef.xmp 190921_094713_dse_7907.nef 190921_094713_dse_7907.nef.xmp 190921_094717_dse_7908.nef 190921_094717_dse_7908.nef.xmp 190921_094805_dse_7910.nef 190921_094805_dse_7910.nef.xmp 190921_094831_dse_7915.nef 190921_094831_dse_7915.nef.xmp 190921_094834_dse_7916.nef 190921_094834_dse_7916.nef.xmp 190921_094834_dse_7917.nef 190921_094834_dse_7917.nef.xmp 190921_094836_dse_7919.nef 190921_094836_dse_7919.nef.xmp 190921_094843_dse_7920.nef 190921_094843_dse_7920.nef.xmp
I'm confused about what has to be converted to what. :-?
the dse_????.nef need to be renamed to match the 190921_??????_dse_????.nef.xmp Per's example worked perfectly after minor adjustments for file locations. case closed, tks -- (paka)Patrick Shanahan Plainfield, Indiana, USA @ptilopteri http://en.opensuse.org openSUSE Community Member facebook/ptilopteri Photos: http://wahoo.no-ip.org/piwigo paka @ IRCnet freenode -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 22/09/2019 15.02, Patrick Shanahan wrote:
* Carlos E.R. <> [09-22-19 07:11]:
On 22/09/2019 04.12, Patrick Shanahan wrote:
I have erred and need help to correct. I need to rename a series of files baseed on another series of files which contain 12 matching characters:
Did you try with krename? It is very powerful. There are recipes on google, too (with krename) on how to do what
yes, but google for krename recipies didn't occur
Right... Maybe I used a different google foo the last time. Some: <https://docs.kde.org/trunk5/en/extragear-utils/krusader/faq_usage.html> ...
190921_094843_dse_7920.nef 190921_094843_dse_7920.nef.xmp
I'm confused about what has to be converted to what. :-?
the dse_????.nef need to be renamed to match the 190921_??????_dse_????.nef.xmp
Ah.
Per's example worked perfectly after minor adjustments for file locations.
case closed, tks
Good! :-) -- Cheers / Saludos, Carlos E. R. (from 15.0 x86_64 at Telcontar)
* Carlos E. R. <robin.listas@telefonica.net> [09-22-19 09:36]:
On 22/09/2019 15.02, Patrick Shanahan wrote:
* Carlos E.R. <> [09-22-19 07:11]:
On 22/09/2019 04.12, Patrick Shanahan wrote:
I have erred and need help to correct. I need to rename a series of files baseed on another series of files which contain 12 matching characters:
Did you try with krename? It is very powerful. There are recipes on google, too (with krename) on how to do what
yes, but google for krename recipies didn't occur
Right... Maybe I used a different google foo the last time.
Some: <https://docs.kde.org/trunk5/en/extragear-utils/krusader/faq_usage.html>
"krusader" ??? -- (paka)Patrick Shanahan Plainfield, Indiana, USA @ptilopteri http://en.opensuse.org openSUSE Community Member facebook/ptilopteri Photos: http://wahoo.no-ip.org/piwigo paka @ IRCnet freenode -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
On 22/09/2019 16.14, Patrick Shanahan wrote:
* Carlos E. R. <robin.listas@telefonica.net> [09-22-19 09:36]:
On 22/09/2019 15.02, Patrick Shanahan wrote:
* Carlos E.R. <> [09-22-19 07:11]:
On 22/09/2019 04.12, Patrick Shanahan wrote:
I have erred and need help to correct. I need to rename a series of files baseed on another series of files which contain 12 matching characters:
Did you try with krename? It is very powerful. There are recipes on google, too (with krename) on how to do what
yes, but google for krename recipies didn't occur
Right... Maybe I used a different google foo the last time.
Some: <https://docs.kde.org/trunk5/en/extragear-utils/krusader/faq_usage.html>
"krusader" ???
Ooops! How the heck did that got in? Yes, it is there in the google search tab. I searched for "krename faq" and the krusader faq is there, first hit. I didn't see it, my mind read what was suposed to be there, not what it actually was. If you search directly at kde docs, what it finds is again krusader. <https://docs.kde.org/docsearch/omega?B=Len&B=XBRANCHGENERICtrunk&DEFAULTOP=and&P=krename&DEFAULTOP=and&xFILTERS=--O> Must be that it is made by the krusade people as a plugin or something :-? Searching for the app krename at kde docs find nothing :-? I know I found it recently /well, this summer), I had need for it. Where? -- Cheers / Saludos, Carlos E. R. (from 15.0 x86_64 at Telcontar)
Hi, all -- ...and then Patrick Shanahan said... % ... % Per's example worked perfectly after minor adjustments for file locations. % % case closed, tks Dang! I knew I'd want to get back to this one sooner than later... I had high hopes my simple shell globbing one-liner would be a favorite ;-) davidtg@u17383850:/tmp/PS> touch `cat list` davidtg@u17383850:/tmp/PS> ls -goh total 4.0K -rw-r--r-- 1 0 Sep 23 22:33 190921_094704_dse_7905.nef -rw-r--r-- 1 0 Sep 23 22:33 190921_094704_dse_7906.nef -rw-r--r-- 1 0 Sep 23 22:33 190921_094713_dse_7907.nef -rw-r--r-- 1 0 Sep 23 22:33 190921_094717_dse_7908.nef -rw-r--r-- 1 0 Sep 23 22:33 190921_094805_dse_7910.nef -rw-r--r-- 1 0 Sep 23 22:33 190921_094831_dse_7915.nef -rw-r--r-- 1 0 Sep 23 22:33 190921_094834_dse_7916.nef -rw-r--r-- 1 0 Sep 23 22:33 190921_094834_dse_7917.nef -rw-r--r-- 1 0 Sep 23 22:33 190921_094836_dse_7919.nef -rw-r--r-- 1 0 Sep 23 22:33 190921_094843_dse_7920.nef -rw-r--r-- 1 0 Sep 23 22:33 dse_7905.nef.xmp -rw-r--r-- 1 0 Sep 23 22:33 dse_7906.nef.xmp -rw-r--r-- 1 0 Sep 23 22:33 dse_7907.nef.xmp -rw-r--r-- 1 0 Sep 23 22:33 dse_7908.nef.xmp -rw-r--r-- 1 0 Sep 23 22:33 dse_7910.nef.xmp -rw-r--r-- 1 0 Sep 23 22:33 dse_7915.nef.xmp -rw-r--r-- 1 0 Sep 23 22:33 dse_7916.nef.xmp -rw-r--r-- 1 0 Sep 23 22:33 dse_7917.nef.xmp -rw-r--r-- 1 0 Sep 23 22:33 dse_7919.nef.xmp -rw-r--r-- 1 0 Sep 23 22:33 dse_7920.nef.xmp -rw-r--r-- 1 480 Sep 23 22:25 list davidtg@u17383850:/tmp/PS> for F in *xmp ; do P=`basename $F .xmp` ; P=`echo *$P` ; echo mv -i "$F" "$P.xmp" ; done mv -i dse_7905.nef.xmp 190921_094704_dse_7905.nef.xmp mv -i dse_7906.nef.xmp 190921_094704_dse_7906.nef.xmp mv -i dse_7907.nef.xmp 190921_094713_dse_7907.nef.xmp mv -i dse_7908.nef.xmp 190921_094717_dse_7908.nef.xmp mv -i dse_7910.nef.xmp 190921_094805_dse_7910.nef.xmp mv -i dse_7915.nef.xmp 190921_094831_dse_7915.nef.xmp mv -i dse_7916.nef.xmp 190921_094834_dse_7916.nef.xmp mv -i dse_7917.nef.xmp 190921_094834_dse_7917.nef.xmp mv -i dse_7919.nef.xmp 190921_094836_dse_7919.nef.xmp mv -i dse_7920.nef.xmp 190921_094843_dse_7920.nef.xmp I originally thought I'd use sed to split the pieces, but then I realized you're just prepending chars onto matching bases and it simplified... Ah, well. Next time :-) HANN :-D -- David T-G See http://justpickone.org/davidtg/email/ See http://justpickone.org/davidtg/tofu.txt -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org
participants (5)
-
Carlos E. R.
-
Carlos E.R.
-
David T-G
-
Patrick Shanahan
-
Per Jessen