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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
03-03-2013, 11:30 AM
|
#1
|
|
Member
Registered: Nov 2003
Posts: 49
Rep:
|
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!
|
|
|
|
03-03-2013, 11:50 AM
|
#2
|
|
Senior Member
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,624
|
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.
|
03-03-2013, 11:50 AM
|
#3
|
|
Senior Member
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,624
|
-- forum double-posted my above response --
|
|
|
|
03-04-2013, 09:35 AM
|
#4
|
|
Member
Registered: Nov 2003
Posts: 49
Original Poster
Rep:
|
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.
|
|
|
|
03-05-2013, 12:50 PM
|
#5
|
|
Senior Member
Registered: Sep 2010
Location: Wales, UK
Distribution: Arch
Posts: 1,624
|
No problem  please mark the thread as 'SOLVED' using the link at the top of the page.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 01:33 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|