Devam Ediyor

bash sed find and replace -- 2

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

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

Daha fazlasını gör: bash sed, bash sed environment, linux bash sed, php, css, html, psd to wordpress, bash sed example, bash sed csv, bash sed log file, bash sed using, bash search replace, bash sed examples, bash sed parser, bash sed simple, bash sed money sign, sed replace, sed replace multi line, sed replace line, sed replace yes

İşveren Hakkında:
( 1 değerlendirme ) Kfar saba, Israel

Proje NO: #10787828

Bu iş için 12 freelancer ortalamada $43 teklif veriyor

yogeshssanwal

Hi there - My name is Yogesh. I’ve read your [login to view URL] team has 4 years experience designing and developing mobile apps and Websites.I would approach your project by starting with wireframes and getting the site complet Daha Fazla

$40 USD in 10 gün içinde
(152 Değerlendirme)
6.6
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 Daha Fazla

$61 USD in 10 gün içinde
(76 Değerlendirme)
6.0
$25 USD in 3 gün içinde
(38 Değerlendirme)
4.9
constantintonu93

Hello! I have experience with C programming and bash scripting. I would try to solve the link replacement problem with bash scripting but I also consider using C if I fail to do it with bash scripts, if you also Daha Fazla

1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% USD
(2 Değerlendirme)
2.0
shahzaib1232

Got 5 years of experience in linux field, working as Server Engineer and wrote tons of bash nagios alerts scripts to detect critical issues before it catches the client attention.

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

nice task, i can help you with IT

$35 USD in 3 gün içinde
(0 Değerlendirme)
0.0
1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% USD
(0 Değerlendirme)
0.0
digidreamsdev

Hi,I am Pritesh and I represent Digital Dreams Technology, India. I have gone through your project requirements for theme development. We have already developed many wordpress themes, plugins and widgets for our cli Daha Fazla

$61 USD in 10 gün içinde
(0 Değerlendirme)
0.0
wyrie

Piece of cake, would love to get it done for you Regards Scott

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

I am a system admininistrator for years and I have experience as developer shell scripts (bash,sh,csh,perl).

$40 USD in 3 gün içinde
(0 Değerlendirme)
0.0
vw7877782vw

A proposal has not yet been provided

$35 USD in 2 gün içinde
(0 Değerlendirme)
0.0
$34 USD in 10 gün içinde
(0 Değerlendirme)
0.0