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


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

find . -name "*.html" > [login to view URL]

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

Thank you

Evner: Linux, MySQL, System Administrator, Web Sikkerhed, WordPress

Se mere: 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

Om arbejdsgiveren:
( 1 bedømmelse ) Kfar saba, Israel

Projekt ID: #10787828

13 freelancere byder i gennemsnit $47 på dette job


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 Flere

$40 USD in 10 dage
(144 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 Flere

$100 USD in 0 dage
(126 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 Flere

$61 USD in 10 dage
(76 bedømmelser)
$25 USD in 3 dage
(38 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 Flere

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

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 Flere

$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)