bash sed find and replace

Kapalı İlan edilme: 7 yıl önce Teslim sırasında ödenir
Kapalı Teslim sırasında ödenir

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

now files name as [login to view URL], [login to view URL] 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" > [login to view URL]

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 < [login to view URL]

Thank you

Linux MySQL Sistem Yöneticisi Web Güvenliği WordPress

Proje NO: #10788103

Proje hakkında

17 teklif Uzak proje Aktif 7 yıl önce

Bu iş için 17 freelancer ortalamada $52 teklif veriyor

techwelfare

Yes Sir let's explore the requirement to clarify in details also if you want us to share our skill and previous work let us know.. hope to hear you soon.. Thanks & Regards Moumita

$136 USD in 4 gün içinde
(103 Değerlendirme)
6.7
zkutch

Hello. More 20 years programming experience. I need more details to set real time and price. Regards. -------------------------------------------------------------------------------------------------------------- Daha Fazla

$50 USD in 5 gün içinde
(17 Değerlendirme)
4.6
crypthne

I have bachelor and master degrees in IT. My Primary skills include Java, Python, VB/.NET, ArcGIS, and PHP. Also database skills include MS Access, MySQL, and Oracle. My Other skills include server and network administ Daha Fazla

1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% USD
(17 Değerlendirme)
3.6
djuranovski

A proposal has not yet been provided

$35 USD in 3 gün içinde
(11 Değerlendirme)
3.3
trhoan00

Hello, I'm a bash, perl developer. I think this task should be written with perl. Thank you for reading my bid

$50 USD in 2 gün içinde
(9 Değerlendirme)
3.2
agarwaladitya007

Have a decade of devops experience. Can do this for you in a short time after confirmation. And you need to pay me once your are satisfied with the work. No ratings as I am new to Freelancer. So I will also need a 5 st Daha Fazla

$30 USD in 10 gün içinde
(1 Yorum)
1.1
vladgenyl

Hello! Can do this task for you very quickly. I have wide experience in writing utilities on C++/C#/PHP (including client-servers scripts, web scraping, monitoring and control systems, and so on) for sites that have Daha Fazla

1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% USD
(0 Değerlendirme)
0.0
hfdmine

I can do this in two hours, I have made made many sophisticated Bash scripts for my company and for my personal needs. Contact me for more informations.

1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% USD
(0 Değerlendirme)
0.0
okmdlukman

Hi, I can complete you project within a day. pleas ping me if you are interested so that we can discuss and will provide the script as per your need post testing it.

1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% USD
(0 Değerlendirme)
0.0
tarique012

script will replace the folder/file names with those given.

$55 USD in 2 gün içinde
(0 Değerlendirme)
0.0
aizuddinzali

A proposal has not yet been provided

$50 USD in 5 gün içinde
(0 Değerlendirme)
0.0