LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-11-2010, 12:50 AM   #31
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757

Quote:
Originally Posted by Crowey View Post
No offense mate, but its not trivial to me, or to the organisation I work for.

I stated clearly at start that I'm a gumby at this - I'm learning bash as quickly, and as in-depth, as I can.

Some folks are helping, and I'm VERY grateful.

But if you don't want to help ...
And there is a trivial solution to your problem - just not with the tools that you have available on your system, which complicates things.
 
Old 05-11-2010, 12:55 AM   #32
Crowey
Member
 
Registered: Jun 2006
Location: Perth, WA
Distribution: RHEL
Posts: 37

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by crts View Post
And there is a trivial solution to your problem - just not with the tools that you have available on your system, which complicates things.
Um do you mean because of old (RHEL) distribution, or do you mean higher level languages? We have Perl (5.8.5), PHP (4.3.9) and Python (2.3.4) all running on this server - would one (any one?) of those been better for this?
 
Old 05-11-2010, 12:56 AM   #33
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Crowey View Post
No offense mate, but its not trivial to me, or to the organisation I work for.

I stated clearly at start that I'm a gumby at this - I'm learning bash as quickly, and as in-depth, as I can.

Some folks are helping, and I'm VERY grateful.

But if you don't want to help ...
Why 'bash' ?
 
Old 05-11-2010, 12:56 AM   #34
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Crowey View Post
Um do you mean because of old (RHEL) distribution, or do you mean higher level languages? We have Perl (5.8.5), PHP (4.3.9) and Python (2.3.4) all running on this server - would one (any one?) of those been better for this?
Yes, for example, Perl.
 
Old 05-11-2010, 12:59 AM   #35
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by grail View Post
Ok ... just thought of something (be gentle if I have missed something - again), but how about:

Code:
while read dir
do
    mv "$dir" "${dir%:2F*}"
done< <(find /Data/ -type d -name '*:2F*' | sort -r)
Hi grail,

I tried your code and it worked without giving any errors. However, it just chopped the rest of the name after ':2F'. So I tried
Code:
while read dir
do
    mv "$dir" "${dir//:2F/-}"
#    mv "$dir" "${dir/:2F/-}"
done< <(find /Data/ -type d -name '*:2F*' | sort -r)
This also had the problem with non-existing directories afterwards.

Last edited by crts; 05-11-2010 at 01:47 AM. Reason: corrected some typos
 
Old 05-11-2010, 01:06 AM   #36
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by Sergei Steshenko View Post
Why 'bash' ?
Why not 'Bash'?
 
Old 05-11-2010, 01:12 AM   #37
Crowey
Member
 
Registered: Jun 2006
Location: Perth, WA
Distribution: RHEL
Posts: 37

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by Sergei Steshenko View Post
Why 'bash' ?
Because I have no programming background at all.

I'm an old NetWare admin, forced, though not unwillingly, to re-skill as a linux sys admin - so while I've been at this a little while now, there is so much to learn.

I want to learn perl (I've even recently bought a couple of O'Reilly perl books), but reality is at the moment I can't programme in it ... AND I thought I was close in my original little shell script and that I would just need a couple of little pointers to get me on the right track.

I didn't start this expecting anybody to write a script for me, and I'm sorry that it turned out to be far more involved than I thought - though I'm pleased that I have a result that I can apply to our system to fix quite a few poorly named directories.
 
Old 05-11-2010, 01:13 AM   #38
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by crts View Post
Why not 'Bash'?
Because dealing with ' ' and ':' is fighting with sh/bash.

Perl has plain 'rename' which is standard "C" library function binding.

Perl has File::find module: http://perldoc.perl.org/File/Find.html .

Perl has built-in regular expressions.

Perl is a compiler, so all the syntax errors are visible at once.
 
Old 05-11-2010, 01:35 AM   #39
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by crts View Post
Code:
    mv "$dir" "${dyr//:2F/-}"
Should dyr be dir?
 
Old 05-11-2010, 01:39 AM   #40
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Crowey View Post
Because I have no programming background at all.

I'm an old NetWare admin, forced, though not unwillingly, to re-skill as a linux sys admin - so while I've been at this a little while now, there is so much to learn.

I want to learn perl (I've even recently bought a couple of O'Reilly perl books), but reality is at the moment I can't programme in it ... AND I thought I was close in my original little shell script and that I would just need a couple of little pointers to get me on the right track.

I didn't start this expecting anybody to write a script for me, and I'm sorry that it turned out to be far more involved than I thought - though I'm pleased that I have a result that I can apply to our system to fix quite a few poorly named directories.
You were not learning. You were running code written by others and reporting back problems.

Learning is implementing the task step by step and debugging should problems occur.

Debugging is finding the first place in the flow which behaves not as expected and finding out why.
 
Old 05-11-2010, 01:44 AM   #41
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by Sergei Steshenko View Post
Because dealing with ' ' and ':' is fighting with sh/bash.

Perl has plain 'rename' which is standard "C" library function binding.

Perl has File::find module: http://perldoc.perl.org/File/Find.html .

Perl has built-in regular expressions.

Perl is a compiler, so all the syntax errors are visible at once.
Good point, I guess. I am not familiar with perl. So what's wrong with this solution
Code:
find /path/to/dir -depth -type d \! -iregex '.*/\..*' -name "*:2F*" -execdir rename 's/:2F/-/g' '{}' \;
provided in this earlier post? This only failed because the OP has an old version of find and another version of rename.
If there is a simpler solution with perl then please, by all means, provide it. We are all eager to learn.
 
Old 05-11-2010, 01:46 AM   #42
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by catkin View Post
Should dyr be dir?
Yes, I tested it against directory 'dir' on my system. So to avoid confusion I renamed the variable to 'dyr'. Forgot to change it back before copy+pasting.
 
Old 05-11-2010, 02:02 AM   #43
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by crts View Post
Good point, I guess. I am not familiar with perl. So what's wrong with this solution
Code:
find /path/to/dir -depth -type d \! -iregex '.*/\..*' -name "*:2F*" -execdir rename 's/:2F/-/g' '{}' \;
provided in this earlier post? This only failed because the OP has an old version of find and another version of rename.
If there is a simpler solution with perl then please, by all means, provide it. We are all eager to learn.
I'm saying it again, this whole thread looks very much like a soap opera.

For example, regarding

Quote:
This only failed because the OP has an old version of find and another version of rename
- GNU 'findutils' as well as GNU 'coreutils' and apparently 'util-linux' depend on "nothing" (i.e. depend on standard "C" library) and can be compiled and installed into a directory of choice using the standard

./configure --prefix=/whatever/desired/prefix
make
make install

sequence.

No programming experience is necessary to run the above sequence.
 
Old 05-11-2010, 02:16 AM   #44
crts
Senior Member
 
Registered: Jan 2010
Posts: 2,020

Rep: Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757Reputation: 757
Quote:
Originally Posted by Sergei Steshenko View Post
I'm saying it again, this whole thread looks very much like a soap opera.

For example, regarding



- GNU 'findutils' as well as GNU 'coreutils' and apparently 'util-linux' depend on "nothing" (i.e. depend on standard "C" library) and can be compiled and installed into a directory of choice using the standard

./configure --prefix=/whatever/desired/prefix
make
make install

sequence.

No programming experience is necessary to run the above sequence.
As the OP stated, he has only little experience with linux. So compiling is out of the question.

Further you criticized that bash is not suited for that task at all.
Quote:
replacing three characters and renaming a directory is trivial in any programming language.
and
Quote:
Why 'bash' ?
So again, please show us a simpler and more elegant solution with perl.
Unless you don't want to in order to keep the soap opera going. Well, at least we keep you entertained.
 
Old 05-11-2010, 02:21 AM   #45
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,005

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
Well, firstly, my bad as again I am without the ability to RTFQ - sorry
I was happily trying to get rid of all after and not replace with a dash
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Renaming directories with Regex? Possible? smaddox Linux - General 9 11-09-2009 06:34 PM
renaming directories from upper case to lower case, help!! linux_teller Linux - Newbie 3 03-07-2008 05:15 AM
Bash - Mass file renaming problem smudge|lala Linux - Software 2 02-14-2007 06:02 PM
dumb newbie question about renaming directories Lleb_KCir Linux - General 2 10-26-2004 08:37 PM
Mandrake File Renaming Problem omega147 Mandriva 15 10-21-2003 12:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration