Find Jobs
Hire Freelancers

bash sed find and replace -- 2

$20-50 USD

进行中
已发布将近 8 年前

$20-50 USD

货到付款
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
项目 ID: 10787828

关于此项目

12提案
远程项目
活跃8 年前

想赚点钱吗?

在Freelancer上竞价的好处

设定您的预算和时间范围
为您的工作获得报酬
简要概述您的提案
免费注册和竞标工作
12威客以平均价$43 USD来参与此工作竞价
用户头像
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 agree. Please contact me so we can discuss more details. I would be glad to help you with this script :).
$50 USD 在1天之内
4.3 (2条评论)
2.0
2.0
用户头像
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 在5天之内
0.0 (0条评论)
0.0
0.0
用户头像
nice task, i can help you with IT
$35 USD 在3天之内
0.0 (0条评论)
0.0
0.0
用户头像
Piece of cake, would love to get it done for you Regards Scott
$45 USD 在1天之内
0.0 (0条评论)
0.0
0.0
用户头像
I am a system admininistrator for years and I have experience as developer shell scripts (bash,sh,csh,perl).
$40 USD 在3天之内
0.0 (0条评论)
0.0
0.0
用户头像
A proposal has not yet been provided
$35 USD 在2天之内
0.0 (0条评论)
0.0
0.0

关于客户

ISRAEL的国旗
Kfar saba, Israel
5.0
1
付款方式已验证
会员自1月 8, 2012起

客户认证

谢谢!我们已通过电子邮件向您发送了索取免费积分的链接。
发送电子邮件时出现问题。请再试一次。
已注册用户 发布工作总数
Freelancer ® is a registered Trademark of Freelancer Technology Pty Limited (ACN 142 189 759)
Copyright © 2024 Freelancer Technology Pty Limited (ACN 142 189 759)
加载预览
授予地理位置权限。
您的登录会话已过期而且您已经登出,请再次登录。