- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: sed search and replace
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2008 11:55 PM
08-18-2008 11:55 PM
I have a lot of .html files that i need to edit though crontab.
This is the string I am looking for:
src="*../something/styleAssets.somthing.something*"
src='*../something/styleAssets.somthing.something*'
href="*../something/styleAssets.somthing.something*"
href='*../something/styleAssets.somthing.something*'
to be replaced with a string:
http:/mydomain.com/styleAssets
I were thinking of something like this:
for i in $(find /www/myDir -type f -name '*.html')
do
sed -e 's/styleAssets/http:\/\/mydomain.com\/styleAssets/g' $i > $i.new
cp $i.nw $i
done
But that is not correct since i need to replace all within the single or double quote.
tnx.
Solved! Go to Solution.
- Tags:
- escape sequences
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2008 12:37 AM
08-19-2008 12:37 AM
Re: sed search and replace
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2008 12:39 AM
08-19-2008 12:39 AM
Re: sed search and replace
Try using escape characters.
http://archives.devshed.com/forums/unix-linux-135/sed-regular-expression-search-replace-help-373459.html
http://www.unix.com/shell-programming-scripting/44886-shell-script-find-replace-string-multiple-files.html
http://www.jonasblog.com/2006/05/search-and-replace-in-all-files-within-a-directory-recursively.html
I think one of the links will work for you.
SEP
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2008 01:39 AM
08-19-2008 01:39 AM
Re: sed search and replace
text:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
should bee changed to something like this.
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
And only if the reference hold the text styleAssets to begin with.
BR jt
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2008 02:18 AM
08-19-2008 02:18 AM
Re: sed search and replace
sed -e 's;".*/styleAssets\..*\..*\..*";"http://mydomain.com/styleAssets";g' \
-e "s;'.*/styleAssets\\..*\\..*\\..*';'http://mydomain.com/styleAssets';g" \
$i
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2008 02:59 AM
08-19-2008 02:59 AM
Re: sed search and replace
Input file:
Perl script href.pl:
s/href=(["'][^"']+["'])/href=\"http:\/\/mydomain.com\/styleAssets\"/ig
Perl script src.pl:
s/src=(["'][^"']+["'])/src=\"http:\/\/mydomain.com\/styleAssets\"/ig
The run script:
for i in $(find ./ -type f -name '*.html')
do
perl -p -i.old1 href.pl $i
perl -p -i.old2 scr.pl $i
done
But this solution also change lines witch does not hold a reference to styleAssets.
I need some "if" statement in the perl script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2008 03:14 AM
08-19-2008 03:14 AM
Re: sed search and replace
# perl -pi.old -e 's{((src|href)=")\.\..([^"]+")}{$1http:/mydomain.com/$2}' file
...which also preserves the original file as "file.old".
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2008 12:12 AM
08-20-2008 12:12 AM
Re: sed search and replace
Hey James your perl works partly except that it changes everything between the quotes even if it does not hold the word styleAssets.
I'm trying to make the changes but it seems that I need some help with that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2008 01:30 AM
08-20-2008 01:30 AM
Solution> Hey James your perl works partly except that it changes everything between the quotes even if it does not hold the word styleAssets.
Oops, sorry about that.
# perl -pi.old -e 's{((?:src|href)=")\.\.(/styleAssets[^"])}{$1http:/mydomain.com$2}' file
Regards!
...JRF...
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2008 03:41 AM
08-20-2008 03:41 AM
Re: sed search and replace
Perl file (file.pl):
s/(href|src)(=["']).+(tyleAssets)/\1\2http:\/\/mydomain.com\/s\3/ig
Run command:
for i in $(find ./ -type f -name '*.html')
do
perl -p -i.old file.pl $i
done
thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2008 03:46 AM
08-20-2008 03:46 AM
Re: sed search and replace
I will try to work on the post from Kevin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2008 05:36 AM
08-20-2008 05:36 AM
Re: sed search and replace
cat filename
src="*../something/styleAssets.somthing.something*"
src='*../something/styleAssets.somthing.something*'
href="*../something/styleAssets.somthing.something*"
href='*../something/styleAssets.somthing.something*'
sed 's/\*.*styleAssets.*$/http\:\/mydomain.com\/styleAssets"/g' filename
rgds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2008 05:09 AM
08-22-2008 05:09 AM
Re: sed search and replace
Because I was matching the explicit "." you had.
Try this, it uses the [^"] trick:
sed -e 's;".*/styleAssets/[^"]*";"http://mydomain.com/styleAssets";' \
-e "s;'.*/styleAssets/[^']*';'http://mydomain.com/styleAssets';" $i
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2008 04:12 AM
09-24-2008 04:12 AM