rename folder
hi guys
i have a about 1000 directories like these and i want to rename all of them to be like output input directories Code:
p8( 18.30 - 19 ) Code:
p8( 18.20 - 18.50 ) i wrote a simple code but i dont know how to expand that for this work for example to change all 18 to 17.50 Code: find . -type d | while read FILE do echo "$FILE" | grep 18 | sed 's/18/17.50/g' done and so on but my code does not make sense because 18 should be a counter from 1 to 23 and every time change in grep and sed to rename all directories . or find numbers in directories' name with awk and wrote a case to check $2 and $4 and change all of them find . -type d | while read FILE do echo "$FILE" |awk '/-/ { print $2 $4 } done any one have any idea to rename all that directories like output ??? any idea ???? |
I am not finding your explanation to be clear. Are the directory names the string of this formula like "p8( 18.30 - 19 )" with the spaces and parenthesis characters? And you want to change "19" to "18.50" in all directory names that have "19"? By rename do you mean the "mv" command? or are you just wanting a string substitution for output purposes (no change to the filesystem)?
|
actually directories are like
P1 ( 9 - 10 ) = 111 P3 ( 17 - 19 ) = 113 P5 ( 2 - 4 ) = 115 P1 ( 22.30 - 23 ) = 111 numbers represent hour . i want to substitute all number with new value and mv all directories . for example P3 ( 17 - 19 ) = 113 should rename to P3 ( 16.50 - 18.50 ) = 113 P3 ( 14 - 18 ) = 113 should rename to P3 ( 13.50 - 17.50 ) = 113 if directories were like p2( 14 - 18 ) i can detect 14 and 18 with sed d1 and d2 shows that Code:
find . -type d -name "p*" | while read i i want to use sed instead of awk ! |
You already have a good answer here :
http://www.linuxquestions.org/questi...ce-4175477266/ try not to post same question multiple times. Please mark the thread as SOLVED. |
I know you said you don't want awk, but it is a better fit than sed
this is really dumb.... but I think does what you want. assumptions made,
Code:
find . -maxdepth 1 -type d -name "??*" | while read DIR;do awk '{ it is at best a cheap fix really you should fix whatever creates the directories in the first place show us the 'big picture' and we can fix it |
thx guys for help
i wrote a script but i have a simple problem with that i want to substitute some variables with new value i used below code for substitution but didn't work echo "P1 ( 13 - 15 ) = 110" | awk '( $3 = "$i1" ) { $5 = "$i2" } {print} ' in this thread http://www.linuxquestions.org/questi...ce-4175477266/ shivaa wrote a script to solve my problem but that did not work too !!! Code:
echo "P1 ( 13 - 15 ) = 110" | awk '{gsub($3,"$i1",$3) && gsub($5,"$i2",$5); print $0}' P1 ( 13.10 - 15.10 ) = 110 for example i1=13.10 and i2=15.10 any opinion ?? |
Where do 'i1' and 'i2' come from?
On a side note, whilst I know anyone create whatever they want, this has to be some of the more bizaar directory naming conventions. One could easily see issues occurring at a later date |
Quote:
i1=$(date --date="${d1} 10 minutes " "+%H.%M" i2=$(date --date="${d2} 10 minutes " "+%H.%M" |
Quote:
I was under the impression you wanted to 'take off' 10mins ( the awk I gave does that ) But here you are adding 10mins this will (almost) do what you want Code:
i1=13.10 Code:
P1 ( 13.1 - 15.1 ) = 110 Code:
echo "P1 ( 13 - 15 ) = 110" | awk '( $3 = '${i1}' ) { $5 = '${i2}' } {printf "%s %s %.2f %s %.2f %s %s %s\n",$1,$2,$3,$4,$5,$6,$7,$8}' Code:
P1 ( 13.10 - 15.10 ) = 110 what are your rules for reassigning 'the numbers' In the long run it is probably easier if we see the whole of your script Would also be nice to know why you need to do this in the first place. is it a 'one off' or is this something you need to do routinely. |
thx i solve the problem
Code:
use '' instead of "" that works !!!!!!!! |
Not to be too nit picky, but, if you are going to replace all of $[35] in the $[35] field with something, wouldn't it be easier to just say:
Code:
$3 = $m1 Also, what is the point of the &&? There is no test nor action being performed based on this expression, so it would seem to serve no purpose |
All times are GMT -5. The time now is 10:56 PM. |