Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Using sed to create a directory

Status
Not open for further replies.

kellnerp

Mechanical
Feb 11, 2005
1,141
0
0
US
That thread was closed without an answer. Here is the key to what he was trying to do, not the whole solution.

jmarkus (Mechanical) said:
25 Feb 04 14:52
I have a file: 12345-6789A.prt
I would like to create a directory: 12345-6789+A/

If I have 50 similarily named files (#####-####X.prt) I would like to create 50 directories.

I think I can use sed, for example:

for file in *;
do mkdir `echo $file | sed 's/'$1'/'$2'/g'` ;
done

where $1 is "12345-6789" and $2 is "12345-6789+", but I don't know how to make $1 and $2 be what I want.

Can someone help?

Thanks,
Jeff
Maybe this would help:
Code:
ls -X *.jpg | sed -r s/"^(.+)(\.jpg)"/"\1\/&"/
ls was used to get some meaningful input and sed's output was dumped to stdout just for testing. The idea for the regex came from Vladimir.

The rename command might do what the OP wanted more simply.

TOP
CSWP, BSSE
Phenom IIx6 1100T = 8GB = FX1400 = XP64SP2 = SW2009SP3
"Node news is good news."
 
Status
Not open for further replies.
Back
Top