LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-03-2013, 11:30 AM   #1
Darrell22
Member
 
Registered: Nov 2003
Posts: 83

Rep: Reputation: 15
Question 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!
 
Old 03-03-2013, 11:50 AM   #2
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
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,
 
1 members found this post helpful.
Old 03-03-2013, 11:50 AM   #3
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

Rep: Reputation: 346Reputation: 346Reputation: 346Reputation: 346
-- forum double-posted my above response --
 
Old 03-04-2013, 09:35 AM   #4
Darrell22
Member
 
Registered: Nov 2003
Posts: 83

Original Poster
Rep: Reputation: 15
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.
 
Old 03-05-2013, 12:50 PM   #5
Snark1994
Senior Member
 
Registered: Sep 2010
Distribution: Debian
Posts: 1,632
Blog Entries: 3

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


Reply

Tags
replace, sed



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
sed search and replace question the_rhino Linux - General 3 12-10-2012 03:25 AM
Using sed - search and replace seebee Programming 5 06-07-2011 09:47 PM
[SOLVED] Using sed to search and replace backwards jimieee Programming 15 10-25-2010 10:13 AM
sed search replace tomerbd1 Linux - General 9 04-10-2008 04:31 AM
sed question for search and replace jakev383 Linux - General 8 05-05-2007 05:40 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:34 AM.

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