Index

Subject : LUG: Using sed to mass rename files

From : "Daniel Underwood" <daniel.underwood@ncsu.[redacted]>

Date : Wed, 03 Mar 2010 03:00:15 -0500


+-----------+
| Objective |
+-----------+

Change these filenames:

F00001-0708-RG-biasliuyda
F00001-0708-CS-akgdlaul
F00001-0708-VF-hioulgigl

to these filenames:

F0001-0708-RG-biasliuyda
F0001-0708-CS-akgdlaul
F0001-0708-VF-hioulgigl

+------------+
| Shell Code |
+------------+

To test:

ls F00001-0708-*|sed 's/\(.\).\(.*\)/mv & \1\2/'

To perform:

ls F00001-0708-*|sed 's/\(.\).\(.*\)/mv & \1\2/' | sh

+---------------+
| My Question |
+---------------+

I don't understand the sed code. I understand what the substitution
command

$ sed 's/something/mv'

means. And I understand regular expressions somewhat. But I don't
understand what's happening here:

\(.\).\(.*\)

or here:

& \1\2/

The former, to me, just looks like it means: "a single character,
followed by a single character, followed by any length sequence of a
single character"--but surely there's more to it than that. As far as
the latter part:

& \1\2/

I have no idea. I really want to understand this code. Please help me
out here, guys.

TIA,
Daniel
--
Daniel Underwood
North Carolina State University
Graduate Student - Operations Research
email: daniel.underwood@ncsu.[redacted]
phone: XXX.302.3291
web: http://www4.ncsu.edu/~djunderw/



Replies :