I gang

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 [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:


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

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

while read -r filepath ;


# Considering the subfolder can have spaces,

# We will start by separating the filename

# And dirname

folderpath=`dirname "$filepath"`

filename=`basename "$filepath"`


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:
( 1 bedømmelse ) Kfar saba, Israel

Projekt-ID: #10787828

14 freelancers are bidding on average $47 for this job


Hi there - My name is Yogesh. I’ve read your [url removed, login to view] 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 Mere

$40 USD in 10 dage
(108 bedømmelser)

Hello, my name is Nikos and I'm working on the Linux server administration field for the past 5 years. Over these years I was responsible for two web hosting companies, managing at full their servers and providing cust Mere

$100 USD in 0 dage
(90 bedømmelser)

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

$61 USD in 10 dage
(76 bedømmelser)
$25 USD in 3 dage
(22 bedømmelser)

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 Mere

$50 USD på 1 dag
(2 bedømmelser)

Hi I have been working on linux and shell scripting since last three years an I can do it Within given period of time.

$35 USD in 10 dage
(1 bedømmelse)

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

nice task, i can help you with IT

$35 USD in 3 dage
(0 bedømmelser)
$40 USD på 1 dag
(0 bedømmelser)

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 Mere

$61 USD in 10 dage
(0 bedømmelser)

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

$45 USD på 1 dag
(0 bedømmelser)

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

$40 USD in 3 dage
(0 bedømmelser)

A proposal has not yet been provided

$35 USD in 2 dage
(0 bedømmelser)
$34 USD in 10 dage
(0 bedømmelser)