Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Easy Phyton Question
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
strubbldesign
Guru
Guru


Joined: 16 Jan 2005
Posts: 354
Location: still somewhere in the matrix but once i was able to look out of it

PostPosted: Mon Mar 25, 2013 5:51 pm    Post subject: Easy Phyton Question Reply with quote

Hy Everybody!

I got a lot of compressed data strucktured this way...
Quote:
Achriv-Folder
Project1
....Data.00r
....Data.01r
....Data.02r
...
....Data.rar

Project2
....Data.00r
....Data.01r
....Data.02r
...
....Data.rar

Project3
....Data.00r
....Data.01r
....Data.02r
...
....Data.rar

....


I managed to extract all the files to the same directory by doing this:
Code:

for f in Project*/*rar; do unrar e "$f" .; done

... well here starts the Questioning...
I have to extract the files to its "Parrent-Directories-Name" i.e. ..../Project3/data4.txt

The other thing is...
I am looking for a Method that copies all theese extracted files to a fifferent location renaming them from i.e. data4.txt to Data4.txt

Code:

for f in Project*/*.txti; do cp -v "${????? f% ????}.????"; done

Thanks for you help
_________________
Always look on the bright side of live. badu badubadubado
Back to top
View user's profile Send private message
leo.the_zoo
Tux's lil' helper
Tux's lil' helper


Joined: 04 Jul 2005
Posts: 146
Location: Poland

PostPosted: Mon Mar 25, 2013 7:52 pm    Post subject: Reply with quote

Why don't you do the following:
Code:
for d in Project*; do cd $d; unrar e Data.rar; cd ..; done

I guess for a split archive you only need to unrar the base file, right?.

Then renaming data4.txt->Data4.txt would be a bit more complicated:
Code:
for f in Project1; do cp -v $f $(echo -n ${f:0:1} | tr 'a-z' 'A-Z';echo ${f:1:$((${#f}-1))}); done

Probably someone will propose something simpler :D

I'd suggest to go for a dry run before you actually rename the files.

Oh... btw where is Python? I only see Bash here :)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum