En cours

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

Compétences : Linux, MySQL, Administration Système, Sécurité Web, WordPress

en voir plus : 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

Concernant l'employeur :
( 1 commentaire ) Kfar saba, Israel

Nº du projet : #10787828

12 freelance font une offre moyenne de $43 pour ce travail

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 Plus

%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 10 jours
(152 Commentaires)
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 Plus

%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 10 jours
(76 Commentaires)
6.0
%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 3 jours
(38 Commentaires)
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 Plus

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(2 Commentaires)
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.

%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 5 jours
(0 Commentaires)
0.0
pshemol

nice task, i can help you with IT

%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 3 jours
(0 Commentaires)
0.0
%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(0 Commentaires)
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 Plus

%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 10 jours
(0 Commentaires)
0.0
wyrie

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

%bids___i_sum_sub_32% %project_currencyDetails_sign_sub_33% USD en 1 jour
(0 Commentaires)
0.0
licadrp

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

%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 3 jours
(0 Commentaires)
0.0
vw7877782vw

A proposal has not yet been provided

%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 2 jours
(0 Commentaires)
0.0
%bids___i_sum_sub_35% %project_currencyDetails_sign_sub_36% USD en 10 jours
(0 Commentaires)
0.0