0

I have tried so many different sed, mv and rename commands - still I cannot rename these files. There are 50 plus files - I tried commands I found - Help thx

Original filenames:

PAGES_TEST1_SART1.XML
PAGES_TEST2_SART2.XML
PAGES_TEST3_SART3.XML
PAGES_TEST4_SART4.XML

To

PAGES_PROD1_SART1.XML
PAGES_PROD2_SART2.XML
PAGES_PROD3_SART3.XML
PAGES_PROD4_SART4.XML

3 Answers3

2

Using Perl's rename (usable in any OS):

rename -n 's/TEST/PROD/g' ./*TEST*.XML

Remove -n switch, aka dry-run when your attempts are satisfactory to rename for real.

  • Hi thx for ur reply - i tried this and it does not work rename 's/TEST/PROD/g' ./TEST.xml - there is a 1 2 3 4 -- please look above - I forgot to put that in the name of the files - does that make a difference to ur commnd? – mattandbeyond Jan 30 '24 at 13:21
  • You provided files with UPPERCASE XML extension. Unix* are case sensitives – Gilles Quénot Jan 30 '24 at 16:36
  • the command u shared does not work upper case aside I checked all that before responding to that _ I hope u can amend it – mattandbeyond Jan 30 '24 at 22:07
1

Which rename are you using? With

$ rename --version
rename from util-linux 2.39.3

Starting with:

$ ls -1
PAGES_TEST_SART1.XML
PAGES_TEST_SART2.XML
PAGES_TEST_SART3.XML
PAGES_TEST_SART4.XML
PAGES_TEST_SART5.XML
PAGES_TEST_SART6.XML
PAGES_TEST_SART7.XML
PAGES_TEST_SART8.XML
PAGES_TEST_SART9.XML

You can do:

$ rename TEST PROD *

and get:

$ ls -1
PAGES_PROD_SART1.XML
PAGES_PROD_SART2.XML
PAGES_PROD_SART3.XML
PAGES_PROD_SART4.XML
PAGES_PROD_SART5.XML
PAGES_PROD_SART6.XML
PAGES_PROD_SART7.XML
PAGES_PROD_SART8.XML
PAGES_PROD_SART9.XML
Andy Dalton
  • 13,993
-1

Maybe something along this line (for bash):

for f in \`ls | grep PAGES_TEST\`; do mv $f $(echo $f | sed 's/TEST/PROD/'); done

Note the back ticks.

AdminBee
  • 22,803