Closed

bash sed find and replace - open to bidding

I need a bash script to do this: I have folder that contain html files and subfolders.

now files name as [url removed, login to view], [url removed, login to view] etc.

i want to replace the original file name with the title tag of the file ( instead of the space between the words i would like to add "_". then replace all links in all folder that contain the original name with the new title name.

example of title - <title>admin/environment/php some text</title> change to <title>php_some_text</title>

then to replace all links in all files that contain the old links to the new file name that will be php_some_text.html.

all my needs have a solutions in my script but don't know how to replace the link all over to the new file name. my script:

#!/bin/bash

cd /var/www/clients/client1/web2/web/docs/31/en

find . -name "*.html" > [url removed, login to view]

while read -r filepath ;

do

# Considering the subfolder can have spaces,

# We will start by separating the filename

# And dirname

folderpath=`dirname "$filepath"`

filename=`basename "$filepath"`

# With GNU GREP

new_name=$(grep -oP '<title>\K.+?</title>' "$filepath" | sed 's#</title>##' | tr ' ' '_' )

#echo new_name=$(grep -oP '<title>\K.+?</title>' "$filepath" | sed 's#</title>##' | tr ' ' '_' )

# With BSD GREP (for who need the info)

# new_name=$(grep -o '<title>.*</title>' $filepath | sed -e 's/<title>\(.*\)<\/title>/\1/g' | sed -e 's/$filename/$new_name/g' | tr ' ' '_')

#if [[ $new_name = */* ]]; then echo "/${new_name##*}"; else echo "$new_name"; fi

mv -v "$filepath" "$folderpath/`basename $new_name`.html"

### command that i tried to solve the link url issue

#find /var/www/clients/client1/web2/web/docs -type f -exec sed -i 's/$filename/$new_name/g' {} \;

#grep -rl '$filename' /var/www/clients/client1/web2/web/docs/31/en | xargs sed -i 's/$filename/$new_name/g' *.html

#sed -i 's/$filename/$new_name/gi' *.html

done < [url removed, login to view]

Thank you

Skills: Linux, MySQL, System Admin, Web Security, WordPress

See more: title web solutions, how to find solutions, BSD to HTML, software testing, html, shell script

About the Employer:
( 1 review ) Kfar saba, Israel

Project ID: #10796706

14 freelancers are bidding on average $37 for this job

techwelfare

Hello Let's explore the requirement and kindly let us know if you would like us to share our skills & experiences with previous development. Thanks & Regards Moumita

$141 USD in 4 days
(60 Reviews)
6.1
VnBestSolutions

Dear Sir. We claim to get it done perfectly for you EXACTLY in the way you want it - Kindly give we a chance and we will prove myself - Ready to prove our words, let's get it done right away and I mean RIGHT AWAY !! Lo More

$45 USD in 1 day
(63 Reviews)
5.9
$25 USD in 1 day
(30 Reviews)
4.7
thms00

Sir, I've graduated in computing back a few years ago and been working at an ISP whee I hold a sysadmin position. As I need more money - I am back on this website. I have been usinf Linux for 7 years, Ubuntu/Deb More

$35 USD in 1 day
(37 Reviews)
4.5
$35 USD in 1 day
(1 Review)
3.4
rdrehmel

20+ years of programming in Unix-like operating systems like linux. I am proficient in all sorts of shell programming and can solve your problem almost immediately. Best regards, Robert

$30 USD in 1 day
(2 Reviews)
3.5
qentty

Hi, I have the piece of code you need, I did basic testing and it works. I can send it to you imediately. You can see I have passed Shell Script exam. Create a milestone with 100% amount which is 25 USD and I More

$25 USD in 1 day
(3 Reviews)
3.0
constantintonu93

Hello! I have experience with bash scripting. I would like to know more details. Can I make a C program for replacing the html names after changing them? I can do this in bash too. Please contact me :).

$30 USD in 0 days
(0 Reviews)
0.0
$25 USD in 1 day
(0 Reviews)
0.0
$40 USD in 5 days
(0 Reviews)
0.0
AragornandArven

if you are olready renamed files and all what remanes is to change titles inside the html then thats all is one line command inshell using xargs and sed if nothing is done then I can write a script in 30 minutes.

$25 USD in 0 days
(0 Reviews)
0.0
daisynowhere

Sorry, but i think i can make your job done with python... I am not so familiar with bash script yet. If you don't mind, I can try to fix it. Best, Daisy

$25 USD in 1 day
(0 Reviews)
0.0
tarcisiogurgel

YOUR SHELL SCRIPT IS ALREADY DONE!!! Hire me and you will receive it immediately. The script was made in two versions: 1st using grep and sed; 2nd using Perl. As you can see, I am novice at Freelancer.com. This i More

$10 USD in 1 day
(0 Reviews)
0.0
vw7877782vw

i am a linux developer and often creating service using shell script

$26 USD in 1 day
(0 Reviews)
0.0
zerodowntime

I have over 15 years of text processing experience with perl, php, regular expressions, etc. This is what I do on a daily basis, and I can provide a solution in less than 1 hour.

$25 USD in 1 day
(0 Reviews)
0.0