sed: replace string w/address

sed: replace string w/address

Post by john andrew » Sat, 23 Sep 2000 04:00:00



I've thousands of files named something like
00asdf.dbf
00asdf.shx
00asdf.shp
12dkfj.dbf
12dkfj.shx
12dkfj.shp

etc...

i need to rename them so that the number is deleted from the front and
placed  in front of the period, i.e.

asdf00.dbf
dkfj12.dbf

the initial numbers range from one to 20, so I thought I could do
somthing like

/00/s/\./&\./
/1/s/\./&\./
etc...

except, of course, "&" refers back to the string searched for, not the
address.  Is there a way to replace with address?

john

 
 
 

sed: replace string w/address

Post by Derek M. Fly » Sat, 23 Sep 2000 04:00:00



> I've thousands of files named something like
> 00asdf.dbf
> 00asdf.shx
> 00asdf.shp
> 12dkfj.dbf
> 12dkfj.shx
> 12dkfj.shp

> etc...

> i need to rename them so that the number is deleted from the front and
> placed  in front of the period, i.e.

> asdf00.dbf
> dkfj12.dbf

> the initial numbers range from one to 20, so I thought I could do
> somthing like

sed -e 's/^\([0-9]*\)\([a-z]*\)\./\2\1./'

And you can repeat the regexs a fixed number instead of using * if its more
appropriate for your needs:

sed -e 's/^\([0-9][0-9]\)\([a-z][a-z][a-z][a-z]\)\./\2\1./'

 
 
 

sed: replace string w/address

Post by Peter Neuhau » Sat, 23 Sep 2000 04:00:00



> sed -e 's/^\([0-9]*\)\([a-z]*\)\./\2\1./'

> And you can repeat the regexs a fixed number instead of using * if its more
> appropriate for your needs:

> sed -e 's/^\([0-9][0-9]\)\([a-z][a-z][a-z][a-z]\)\./\2\1./'

I'd do it that way...

sed -e 's/^\([0-9]\{2\}\)\(.*\)\./\2\1./'

Peter

 
 
 

sed: replace string w/address

Post by bmar.. » Mon, 25 Sep 2000 04:00:00



   >I've thousands of files named something like
   >00asdf.dbf
   >00asdf.shx
   >00asdf.shp
   >12dkfj.dbf
   >12dkfj.shx
   >12dkfj.shp
   >etc...
   >i need to rename them so that the number is deleted from the front
   >and placed  in front of the period, i.e.
   >asdf00.dbf
   >dkfj12.dbf
   >the initial numbers range from one to 20, so I thought I could do
   >somthing like
   >/00/s/\./&\./
   >/1/s/\./&\./
   >etc...
   >except, of course, "&" refers back to the string searched for, not
   >the address.  Is there a way to replace with address?
   >john
s/\([0-2][0-9]\)\([^.]\)/\2\1/

Net-Tamer V 1.08X - Test Drive

 
 
 

sed: replace string w/address

Post by Ken Pizzi » Wed, 27 Sep 2000 12:14:55



>I've thousands of files named something like
>00asdf.dbf
...
>i need to rename them so that the number is deleted from the front and
>placed  in front of the period, i.e.

Other responses appear to have overlooked this "rename" fragment
of the problem, so I'll offer:
  ls -f | sed -n 's/\([0-9]*\)\(.*\)\(\..*\)/mv & \2\1\3/p' | sh

                --Ken Pizzini

 
 
 

1. Korn Shell: Using sed to replace string with multiline string?

I am trying to use the sed command to replace a single line within a
file with a multi-line string. The command format is:

sed s"/|-insert_data_here-|/$data_string/"

The data_string contain the contents of a file (10 lines).  Sed
returnes the following error message when it encounters the first
newline embedded within data_string.

sed: command garbled:

How can I get sed to treat the data_string as just a stream of
characters without getting hung up on the embedded newline characters?

2. Root Shell Flame Wars!

3. Can I replace a section of string/file using sed?

4. **NOISE W/ Stealth 64 VRAM**

5. Replace string starting from the 2nd occurrence using sed?

6. Linux 2.0.10 and module isdn.o

7. sed help: Replacing a string.

8. Problem with LInuxPPC 2000 instalation (iMAC rev. B)...too slow!!!!

9. ctrl characters in sed replace string

10. Sed - replacing spaces in a string

11. How to replace string with some text (with new lines) sed or something else ?

12. replace a single string in multiple files w/ a shell script + sed

13. Find and replace multiple strings with sed