Re: Search Replace Issue
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Parv wrote: in message [EMAIL PROTECTED], wrote Garrett Cooper thusly... cat file.html | sed -e s|http://www.domain.com||g ... Not really a need for cat(1), just use input redirection ... sed -e '...' file - Parv I just meant in general.. assuming that he used fetch or wget to get the file prior to running the search and replace. - -Garrett -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.1 (FreeBSD) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFkf+qEnKyINQw/HARAmXQAJ0e40U/nXUeaQ1/rZqCchLHWKctjACfaNN+ 0+6mf+Psoc48hn4C9dhK5iw= =+yCc -END PGP SIGNATURE- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
RE: OT: sed usage (was Re: Search Replace Issue)
From: Parv [EMAIL PROTECTED] To: DeepTech [EMAIL PROTECTED] CC: freebsd-questions@freebsd.org Subject: OT: sed usage (was Re: Search Replace Issue) Date: Mon, 25 Dec 2006 00:04:47 -0500 in message [EMAIL PROTECTED], wrote DeepTech thusly... sed -e 's/http\:\/\/www\.domain\.htm\///g' *.htm *.htm That will most likely destroy the original file(s). Depending on your shell, you will get redirection error from the shell if there happen to be more than one file matching the pattern '*.htm'. In particular, in zsh 4.2.6 ... # cat p polka dot # cp -f p q; cp -f p qq # ls -l p q* -rw--- 1 parv people 10 Dec 24 23:32 p -rw--- 1 parv people 10 Dec 24 23:32 q -rw--- 1 parv people 10 Dec 24 23:32 qq # sed -e '' q* | q* # ls -l q* -rw--- 1 parv people 0 Dec 24 23:34 q -rw--- 1 parv people 0 Dec 24 23:34 qq NOTE: not sure if u have to use a '\' before that ':' No, ':' need not be escaped. - Parv sed -e 's/http\:\/\/www\.domain\.htm\///g' *.htm *.htm Although it did not destroy the files, it didn't work, nor did most of the others. However, this one using perl DID work perfectly: perl -pi -e 's/http:\/\/www.cebik.com\///g' *.html None of the other SED(1) tips worked although I tried several times. The above is the only perl tip that worked for my purpose and it worked well. Although the SED(1) tips may have worked if I had enough time to debug, time was a factor. Glad the one worked as it saved an enourmous amount of time on this SR effort. Again, many thanks for all the help! Best Merry Xmas! Jack _ Fixing up the home? Live Search can help http://imagine-windowslive.com/search/kits/default.aspx?kit=improvelocale=en-USsource=hmemailtaglinenov06FORM=WLMTAG ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Search Replace Issue
in message [EMAIL PROTECTED], wrote Josh Paetzel thusly... On Saturday 23 December 2006 21:29, Jack Stone wrote: Appreciate a tip on how to search replace hundreds of *.htm files: From this: lia href=http://www.domain.com/tales/wouf.html To this: lia href=tales/wouf.html perl -p0777i -e 's/http:\/\/www.domain.com\///g' *.htm Is -0777 really necessary (causes whole file to be stored in memory)? But that is not really the point of this reply. Above is a fine opportunity to use alternative delimiters (and to restrict the matching (only to link URLs)) ... perl -pi -e 's!(?=href=)\Qhttp://www.domain.com!!g' *.html ... in case of hundreds of *.htm, use xargs(1) pipeline ... find dir-of-HTML-files -type f -name '*.html' -print0 \ | xargs -0 perl -pi -e 's!(?=href=)\Qhttp://www.domain.com!!g' Feel free to change Perl version with sed (the version of sed with -i option[0]) one ... find ... \ | ... sed -i -e 's,\(href=\)http://www\.domain\.com,\1,g' [0] That makes this reply on point. - Parv -- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Search Replace Issue
OK, specifically, sed -e 's/http\:\/\/www\.domain\.htm\///g' *.htm *.htm The sed command processes files with some regexp stuff, this command removes the http://www.domain.htm/ from htms. NOTE: not sure if u have to use a '\' before that ':' ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Search Replace Issue
From: Parv [EMAIL PROTECTED] To: Josh Paetzel [EMAIL PROTECTED] CC: Jack Stone [EMAIL PROTECTED], freebsd-questions@freebsd.org Subject: Re: Search Replace Issue Date: Sun, 24 Dec 2006 02:56:32 -0500 in message [EMAIL PROTECTED], wrote Josh Paetzel thusly... On Saturday 23 December 2006 21:29, Jack Stone wrote: Appreciate a tip on how to search replace hundreds of *.htm files: From this: lia href=http://www.domain.com/tales/wouf.html To this: lia href=tales/wouf.html perl -p0777i -e 's/http:\/\/www.domain.com\///g' *.htm Is -0777 really necessary (causes whole file to be stored in memory)? But that is not really the point of this reply. Above is a fine opportunity to use alternative delimiters (and to restrict the matching (only to link URLs)) ... perl -pi -e 's!(?=href=)\Qhttp://www.domain.com!!g' *.html ... in case of hundreds of *.htm, use xargs(1) pipeline ... find dir-of-HTML-files -type f -name '*.html' -print0 \ | xargs -0 perl -pi -e 's!(?=href=)\Qhttp://www.domain.com!!g' Feel free to change Perl version with sed (the version of sed with -i option[0]) one ... find ... \ | ... sed -i -e 's,\(href=\)http://www\.domain\.com,\1,g' [0] That makes this reply on point. - Parv Parv and all: Many thanks for these various tips and your time to make them! I usually use sed(1) myself, but for the life of me, I could not find a way to properly apply delimiters or syntax to get it to work. I was close, but no cigar! Too many slashes and commas I guess. Such a tool will indeed be a giant timesaver! Merry Xmas! All the best, Jack _ Get live scores and news about your team: Add the Live.com Football Page www.live.com/?addtemplate=footballicid=T001MSN30A0701 ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Search Replace Issue
Jack Stone wrote: Appreciate a tip on how to search replace hundreds of *.htm files: From this: lia href=http://www.domain.com/tales/wouf.html To this: lia href=tales/wouf.html In other words, I just want the relative path and remove all the extra: http://www.domain.htm/ portions of the lines. Large thanks in advance for help. Happy Holidays! Jack cat file.html | sed -e s|http://www.domain.com||g file.tmp.html mv file.tmp.html file.html -Garrett ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Search Replace Issue
Jack Stone wrote: From: Parv [EMAIL PROTECTED] To: Josh Paetzel [EMAIL PROTECTED] CC: Jack Stone [EMAIL PROTECTED], freebsd-questions@freebsd.org Subject: Re: Search Replace Issue Date: Sun, 24 Dec 2006 02:56:32 -0500 in message [EMAIL PROTECTED], wrote Josh Paetzel thusly... On Saturday 23 December 2006 21:29, Jack Stone wrote: Appreciate a tip on how to search replace hundreds of *.htm files: From this: lia href=http://www.domain.com/tales/wouf.html To this: lia href=tales/wouf.html perl -p0777i -e 's/http:\/\/www.domain.com\///g' *.htm Is -0777 really necessary (causes whole file to be stored in memory)? But that is not really the point of this reply. Above is a fine opportunity to use alternative delimiters (and to restrict the matching (only to link URLs)) ... perl -pi -e 's!(?=href=)\Qhttp://www.domain.com!!g' *.html ... in case of hundreds of *.htm, use xargs(1) pipeline ... find dir-of-HTML-files -type f -name '*.html' -print0 \ | xargs -0 perl -pi -e 's!(?=href=)\Qhttp://www.domain.com!!g' Feel free to change Perl version with sed (the version of sed with -i option[0]) one ... find ... \ | ... sed -i -e 's,\(href=\)http://www\.domain\.com,\1,g' [0] That makes this reply on point. - Parv Parv and all: Many thanks for these various tips and your time to make them! I usually use sed(1) myself, but for the life of me, I could not find a way to properly apply delimiters or syntax to get it to work. I was close, but no cigar! Too many slashes and commas I guess. Such a tool will indeed be a giant timesaver! Merry Xmas! All the best, Jack One thing with regular expressions though, is that you can control the command characters to use with defining the search and replace keywords and replacements. If you see my example, I used pipes because you had a number of forward slashes (/), so it allows you to cut down on the number of escaping backslashes in your regular expression / replacement. Cheers and a Merry Christmas to you too! -Garrett ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
[Fwd: Re: Search Replace Issue]
---BeginMessage--- On Sun, 2006-12-24 at 12:13 -0800, Garrett Cooper wrote: Jack Stone wrote: From: Parv [EMAIL PROTECTED] To: Josh Paetzel [EMAIL PROTECTED] CC: Jack Stone [EMAIL PROTECTED], freebsd-questions@freebsd.org Subject: Re: Search Replace Issue Date: Sun, 24 Dec 2006 02:56:32 -0500 in message [EMAIL PROTECTED], wrote Josh Paetzel thusly... On Saturday 23 December 2006 21:29, Jack Stone wrote: Appreciate a tip on how to search replace hundreds of *.htm files: From this: lia href=http://www.domain.com/tales/wouf.html To this: lia href=tales/wouf.html perl -p0777i -e 's/http:\/\/www.domain.com\///g' *.htm Is -0777 really necessary (causes whole file to be stored in memory)? But that is not really the point of this reply. Above is a fine opportunity to use alternative delimiters (and to restrict the matching (only to link URLs)) ... perl -pi -e 's!(?=href=)\Qhttp://www.domain.com!!g' *.html ... in case of hundreds of *.htm, use xargs(1) pipeline ... find dir-of-HTML-files -type f -name '*.html' -print0 \ | xargs -0 perl -pi -e 's!(?=href=)\Qhttp://www.domain.com!!g' Feel free to change Perl version with sed (the version of sed with -i option[0]) one ... find ... \ | ... sed -i -e 's,\(href=\)http://www\.domain\.com,\1,g' [0] That makes this reply on point. - Parv Parv and all: Many thanks for these various tips and your time to make them! I usually use sed(1) myself, but for the life of me, I could not find a way to properly apply delimiters or syntax to get it to work. I was close, but no cigar! Too many slashes and commas I guess. Such a tool will indeed be a giant timesaver! Merry Xmas! All the best, Jack One thing with regular expressions though, is that you can control the command characters to use with defining the search and replace keywords and replacements. If you see my example, I used pipes because you had a number of forward slashes (/), so it allows you to cut down on the number of escaping backslashes in your regular expression / replacement. Cheers and a Merry Christmas to you too! -Garrett ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] The -i option to sed enables it to rewrite a file in place, removing the need to create new files, delete the old ones, and rename the new ones. But it needs careful testing, and should never be used without a good backup of all the files that it might touch. Powerful tools are often dangerous! ---End Message--- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Search Replace Issue
From this: lia href=http://www.domain.com/tales/wouf.html To this: lia href=tales/wouf.html In other words, I just want the relative path and remove all the extra: http://www.domain.htm/ portions of the lines. ... cat file.html | sed -e s|http://www.domain.com||g file.tmp.html mv file.tmp.html file.html I don't think the cat accomplishes anything in a case like this (and BTW he also wanted to remove the / after com): sed -e s|http://www.domain.com/||g file.html file.tmp.html ... Additional logic (or use of -i) may be desirable to avoid loss of file ownership and permission settings. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Search Replace Issue
in message [EMAIL PROTECTED], wrote Garrett Cooper thusly... cat file.html | sed -e s|http://www.domain.com||g ... Not really a need for cat(1), just use input redirection ... sed -e '...' file - Parv -- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
OT: sed usage (was Re: Search Replace Issue)
in message [EMAIL PROTECTED], wrote DeepTech thusly... sed -e 's/http\:\/\/www\.domain\.htm\///g' *.htm *.htm That will most likely destroy the original file(s). Depending on your shell, you will get redirection error from the shell if there happen to be more than one file matching the pattern '*.htm'. In particular, in zsh 4.2.6 ... # cat p polka dot # cp -f p q; cp -f p qq # ls -l p q* -rw--- 1 parv people 10 Dec 24 23:32 p -rw--- 1 parv people 10 Dec 24 23:32 q -rw--- 1 parv people 10 Dec 24 23:32 qq # sed -e '' q* | q* # ls -l q* -rw--- 1 parv people 0 Dec 24 23:34 q -rw--- 1 parv people 0 Dec 24 23:34 qq NOTE: not sure if u have to use a '\' before that ':' No, ':' need not be escaped. - Parv -- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Search Replace Issue
On Saturday 23 December 2006 21:29, Jack Stone wrote: Appreciate a tip on how to search replace hundreds of *.htm files: From this: lia href=http://www.domain.com/tales/wouf.html To this: lia href=tales/wouf.html In other words, I just want the relative path and remove all the extra: http://www.domain.htm/ portions of the lines. Large thanks in advance for help. Happy Holidays! Jack perl -p0777i -e 's/http:\/\/www.domain.com\///g' *.htm -- Thanks, Josh Paetzel ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Search Replace Issue
Don't know anything concrete, but: regexp or wildcards. ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Search Replace Issue
On Sat, 23 Dec 2006 21:29:40 -0600 Jack Stone [EMAIL PROTECTED] wrote: Appreciate a tip on how to search replace hundreds of *.htm files: From this: lia href=http://www.domain.com/tales/wouf.html To this: lia href=tales/wouf.html In other words, I just want the relative path and remove all the extra: http://www.domain.htm/ portions of the lines. Probably many ways to do this but I typically use sed to edit files in-place: sed -i 's/http:\/\/www.domain.com\///g' *.htm Randy -- ___ freebsd-questions@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]