Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 02-27-2011, 12:29 AM   #1
LQ Newbie
Registered: Apr 2010
Distribution: Ubuntu 10.10
Posts: 8

Rep: Reputation: 0
"find and replace" in shell (includes the / character)


I would like to know what shell command I could use for finding a phrase (which is a URL) in many files, with a different phrase. I have tried the "sed" command, but it does not like the forward slash. Any ideas?
Old 02-27-2011, 12:43 AM   #2
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,826

Rep: Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973Reputation: 1973
If you just want to find a text string, the best tool to use is grep. sed is designed more for modifying strings.

Certain characters such as the slash are considered special by either the shell, the regex engine of the tool you use, or both. In most cases you can escape them by placing a backslash in front of them.

Here are a few useful pages from the Advanced Bash Scripting Guide that may help you. Grep isn't specifically discussed, but most of what you learn can be applied to it.

Here are a few useful bash scripting references:

PS: If you show us the exact command you tried to use, an example of the text you're trying to search through, and the output messages you get, we'll help you come up with a solution. Also, try searching through previous threads on the subject, as this kind of thing comes up often.

Last edited by David the H.; 02-27-2011 at 12:46 AM. Reason: as stated
1 members found this post helpful.
Old 02-27-2011, 02:08 AM   #3
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671Reputation: 671
You can use other characters to separate the LHS and RHS. EG. sed '' url
1 members found this post helpful.
Old 02-28-2011, 08:33 PM   #4
LQ Newbie
Registered: Apr 2010
Distribution: Ubuntu 10.10
Posts: 8

Original Poster
Rep: Reputation: 0
Thanks you two. I will be sure to check out your links later if I need to do so, David the H.

Simply adding forward slashes in front of my backwards slashes solved the problem, but replacing the slashes in the command with a hash was easiest.



Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 07:42 AM
Shell script: Find "\n\t..." to replace a string in a file michael24h7d Programming 8 05-11-2007 03:07 AM
Kopete 0.10.3 "Can't find X includes" SuSE 9.3 kahlil88 Linux - Software 4 08-20-2005 12:36 AM
1. shell script "find and replace" on text 2. java GUI application randomx Programming 4 03-05-2004 01:01 PM
"Can't find X includes" when installing KDE-theme christian-s Linux - Software 3 01-15-2004 12:01 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:42 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration