LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   sed - Search and Replace /phrase (http://www.linuxquestions.org/questions/programming-9/sed-search-and-replace-phrase-4175452521/)

Darrell22 03-03-2013 11:30 AM

sed - Search and Replace /phrase
 
Dear Experts,

I have two files with the output of directory structures:

home_files.txt
backupfat32_files.txt


---

home_files.txt contains rows such as:
/home/notes/linux.txt


backupfat32_files.txt will have an added string on the front:
/backupfat32/home/notes/linux.txt


----

How can I use sed to remove
/backupfat32
???

---

I tried this, but it's not quite:

cat backupfat32_files.txt | sed 's/backupfat32//g'

//home/notes/linux.txt



---

It's an escape character that I need, correct?

Unfortunately, I can't find a webpage with a clear and simple example that works.


Thanks a lot!

Snark1994 03-03-2013 11:50 AM

Code:

cat backupfat32_files.txt | sed 's/\/backupfat32//g'
is what you want, or

Code:

cat backupfat32_files.txt | sed 's@/backupfat32@@g'
(your delimiter character need not be '/'), or

Code:

sed 's@/backupfat32@@g' backupfat32_files.txt
(eliminating the useless use of cat)

Regards,

Snark1994 03-03-2013 11:50 AM

-- forum double-posted my above response --

Darrell22 03-04-2013 09:35 AM

That worked!

I was using cat, so that I wouldn't mess up the file, and it echos to screen.

You answered in only 20 minutes! Cool.

Thanks a lot! I really appreciate it.

Snark1994 03-05-2013 12:50 PM

No problem :) please mark the thread as 'SOLVED' using the link at the top of the page.


All times are GMT -5. The time now is 06:36 PM.