Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations JAE on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using sed to create a directory

Status
Not open for further replies.

kellnerp

Mechanical
Joined
Feb 11, 2005
Messages
1,141
Location
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.

Part and Inventory Search

Sponsor

Back
Top