LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 07-22-2018, 03:43 PM   #1
jaydul
Member
 
Registered: Sep 2012
Posts: 69

Rep: Reputation: Disabled
Question 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.
 
Old 07-22-2018, 04:22 PM   #2
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
It seems your search is case sensitive, no?

[edit] removed an irrelevant question

Last edited by keefaz; 07-22-2018 at 04:24 PM.
 
Old 07-22-2018, 04:25 PM   #3
jaydul
Member
 
Registered: Sep 2012
Posts: 69

Original Poster
Rep: Reputation: Disabled
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
 
Old 07-22-2018, 04:32 PM   #4
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,767

Rep: Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225Reputation: 2225
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.
 
Old 07-22-2018, 05:43 PM   #5
BW-userx
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

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
iname (clue clue clue)
 
1 members found this post helpful.
Old 07-22-2018, 08:55 PM   #6
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
There's a script called 'rename' that might be handy for this.
 
Old 07-22-2018, 09:36 PM   #7
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,386
Blog Entries: 3

Rep: Reputation: 3775Reputation: 3775Reputation: 3775Reputation: 3775Reputation: 3775Reputation: 3775Reputation: 3775Reputation: 3775Reputation: 3775Reputation: 3775Reputation: 3775
Quote:
Originally Posted by AwesomeMachine View Post
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.
 
Old 07-23-2018, 08:11 AM   #8
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,885
Blog Entries: 13

Rep: Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931Reputation: 4931
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.
 
Old 07-23-2018, 09:26 AM   #9
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,389

Rep: Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764Reputation: 2764
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
 
Old 07-23-2018, 10:00 AM   #10
BW-userx
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

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
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
 
Old 07-23-2018, 02:10 PM   #11
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,846

Rep: Reputation: 1222Reputation: 1222Reputation: 1222Reputation: 1222Reputation: 1222Reputation: 1222Reputation: 1222Reputation: 1222Reputation: 1222
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!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] Perform a case-insensitive search for a pattern chtsalid Linux - Newbie 6 01-14-2017 03:14 AM
how to search in VI wih case insensitive lordofring Programming 7 11-16-2011 08:11 AM
Copying files from case-sensitive Linux to case-insensitive Windows via CIFS? SlowCoder Linux - General 4 05-07-2008 07:03 PM
Perl: Search and replace directories within text files Erhnam Programming 2 03-07-2006 04:07 AM
case insensitive search command ColKurtz Linux - Newbie 4 01-20-2005 07:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:48 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