Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
07-22-2018, 03:43 PM
|
#1
|
Member
Registered: Sep 2012
Posts: 69
Rep: 
|
Case insensitive file name search and replace files in sub-directories
I am trying to find case insensitive file names and then replace that particular file with other name.
jaydulWeb.php
Jaydukwebsite.php
JAYDULEditionMenuitem.php
I want to change "jaydul" to "linux"
I want to change "Jaydul" to "Linux"
I want to change "JAYDUL" to "LINUX"
How it possible in linux
http://findandreplace.io/?z=codeplex
Last edited by jaydul; 07-22-2018 at 03:44 PM.
|
|
|
07-22-2018, 04:22 PM
|
#2
|
LQ Guru
Registered: Mar 2004
Distribution: Slackware
Posts: 6,858
|
It seems your search is case sensitive, no?
[edit] removed an irrelevant question
Last edited by keefaz; 07-22-2018 at 04:24 PM.
|
|
|
07-22-2018, 04:25 PM
|
#3
|
Member
Registered: Sep 2012
Posts: 69
Original Poster
Rep: 
|
It seems your search is case sensitive, no?
Files are in Linux and case sensitive.
I dont have perl script
I want use bash scripts to change files name.I dont need find and replace text
|
|
|
07-22-2018, 04:32 PM
|
#4
|
LQ Veteran
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: Rocky 9.6
Posts: 5,906
|
Looks like a task for the find command.
man find
and, maybe search for examples. find is very powerful, but the syntax can be daunting.
|
|
|
07-22-2018, 05:43 PM
|
#5
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
|
iname (clue clue clue)
|
|
1 members found this post helpful.
|
07-22-2018, 08:55 PM
|
#6
|
LQ Guru
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
|
There's a script called 'rename' that might be handy for this.
|
|
|
07-22-2018, 09:36 PM
|
#7
|
LQ Guru
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,756
|
Quote:
Originally Posted by AwesomeMachine
There's a script called 'rename' that might be handy for this.
|
Handy, but the script does not run Rakudo (perl6) so the :samecase modifier is not available. Thus the solution is not self-evident[ *]. However, all the normal perl5 expressions are still available. So assuming no spaces in the file names:
Code:
rename -v -n 's/jaydul/$_^lc($_)^"linux"/ei; tr/ //ds;' *.php
Note that one file name in the example in the OP has a "k" instead of an "l". I am expecting that to have been a typo.
|
|
|
07-23-2018, 08:11 AM
|
#8
|
Moderator
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,968
|
This seems to be more of a question for the Programming forum. However before moving it, I wonder what you've tried.
You've cited some singular examples, also given a link example to a windows utility. All great.
Your follow-up post says you only want to use bash scripting.
Have you tried anything? Have you tried any of the suggestions such as replace or find?
Plenty is possible, however you have to do the work to get it done in the first place and consider if there are some ways to do the modifications easier.
Please give us insight into what you've tried.
|
|
|
07-23-2018, 09:26 AM
|
#9
|
LQ 5k Club
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,575
|
I assume the OP is happy with the 'rename' solution in post #7.
A bash solution (that requires changing 'echo' to 'mv' to be effective)
Code:
for f in [Jj][Aa][Yy][Dd][Uu][Ll]*; do g=${f/jaydul/linux}; g=${g/Jaydul/Linux}; g=${g/JAYDUL/LINUX}; echo "$f" "$g"; done
|
|
|
07-23-2018, 10:00 AM
|
#10
|
LQ Guru
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342
|
Code:
#!/bin/bash
while read f
do
#get name of file
name=${f##*/}
#check its sub string and lowercase everything
if [[ ${name,,} =~ make ]] ;
then
echo $name
#if match make changes using orginal
#path to file.
fi
done <<< $(find ~/ -type f -iname make*)
half baked code
|
|
|
07-23-2018, 02:10 PM
|
#11
|
Senior Member
Registered: Dec 2011
Location: Simplicity
Distribution: Mint/MATE
Posts: 3,052
|
The suggested perl solutions in the post#1 are too advanced for me.
I know awk better. The effort in awk is, well, not too high.
Code:
#!/bin/sh
from=jaydul
to=linux
find . -type f -iname "$from" -print |
awk -v from="$from" -v to="$to" '
BEGIN {
lenfrom=length(from)
Lfrom=tolower(from)
Ufrom=toupper(from)
lento=length(to)
Lto=tolower(to)
Uto=toupper(to)
}
(starti=index(tolower($0),Lfrom)) > 0 {
buf=substr($0,starti,lenfrom)
out=""
for (i=1; i<=lento; i++) {
out=(out ((substr(buf,i,1) == substr(Lfrom,i,1)) ? substr(Lto,i,1) : substr(Uto,i,1)))
}
print "mv", $0, (substr($0,1,starti-1) out substr($0,starti+lenfrom))
}
'
It generates the "mv" commands.
Pipe to sh in order to run them!
|
|
|
All times are GMT -5. The time now is 04:32 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|