Lukket

bash sed find and replace

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

Færdigheder: Linux, MySQL, System Administrator, Web Sikkerhed, WordPress

Se mere: title web solutions, how to find solutions, BSD to HTML, sed bash script sed, sed bash examples, sed bash scripting, sed bash programming word, linux using sed bash script, bash using sed bash script, sed bash, sed bash script, linux sed bash script, using sed bash script

Om arbejdsgiveren:
( 0 bedømmelser ) Ho Chi Minh, Vietnam

Projekt-ID: #10788103

19 freelancers are bidding on average $50 for this job

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 dage
(60 bedømmelser)
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 Mere

$83 USD in 10 dage
(63 bedømmelser)
5.9
Batista111

Hello , I have 5 years experience in Android/ios, php(mysql+html5,css3),wordpress(theme customization,plugin development,plugin integration,API integration) and E-commerce(payment integration,add to cart). I have Mere

$83 USD in 10 dage
(40 bedømmelser)
5.5
zkutch

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

$50 USD in 5 dage
(13 bedømmelser)
4.1
$111 USD in 5 dage
(6 bedømmelser)
3.1
wdworks

Hello! I have around 8 years of linux administration background, and during that period i have automated lot's of tasks using bash or perl and i'l be glad to help you with your task.

$35 USD in 3 dage
(4 bedømmelser)
2.9
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 Mere

$25 USD på 1 dag
(6 bedømmelser)
2.7
djuranovski

A proposal has not yet been provided

$35 USD in 3 dage
(4 bedømmelser)
2.6
SergeyKyiv

Greetings! My name is Sergey Murzin, I'm from Kyiv, Ukraine. I have 25 years experience with programming including 8 years with linux. I can start working with your job immediately to finalise it within 1 day. Mere

$35 USD på 1 dag
(1 bedømmelse)
2.4
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 dage
(8 bedømmelser)
2.4
$30 USD på 1 dag
(0 bedømmelser)
0.0
$50 USD in 3 dage
(0 bedømmelser)
0.0
$40 USD in 10 dage
(0 bedømmelser)
0.0
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 Mere

$30 USD in 10 dage
(0 bedømmelser)
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.

$20 USD på 1 dag
(0 bedømmelser)
0.0
carlosporter

Hello, I'm a System Administrator with 8 years of experience managing Linux servers in different environments and I have acquired several certifications to backup my knowledge. I have worked for several companies Mere

$40 USD in 10 dage
(0 bedømmelser)
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.

$30 USD på 1 dag
(0 bedømmelser)
0.0
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 Mere

$40 USD på 1 dag
(0 bedømmelser)
0.0
tarique012

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

$55 USD in 2 dage
(0 bedømmelser)
0.0
aizuddinzali

A proposal has not yet been provided

$50 USD in 5 dage
(0 bedømmelser)
0.0