LinuxQuestions.org
Help answer threads with 0 replies.
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 06-25-2017, 02:38 PM   #16
Laserbeak
Member
 
Registered: Jan 2017
Location: Manhattan, NYC NY
Distribution: Mac OS X, iOS, Solaris
Posts: 508

Rep: Reputation: 143Reputation: 143

Quote:
Originally Posted by pedropt View Post
Thanks to all other alternatives , i forgot to mention , but i wanted this code using only bash language .
What makes you think that sed is related to bash? It's about as much related as COBOL is...
 
1 members found this post helpful.
Old 06-25-2017, 02:44 PM   #17
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,263
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
Glad that worked.

As noted in my updated post above, I think the original source of confusion is in use of the '<...>' syntax, which is not common regular expression syntax, although it does seem to be a GNU sed extension with its own quirks. On the other hand, '/^...$/' is basic and universally recognized regular expression syntax.

Learn and stick to common regex or pcre syntax for best results, at least until you have a good feel for their use. Here is a good tutorial to start with, many others available online.

If this question is resolved, please mark it solved with the thread tools at top.

Last edited by astrogeek; 06-25-2017 at 02:45 PM. Reason: typo
 
1 members found this post helpful.
Old 06-25-2017, 02:57 PM   #18
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,789

Rep: Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201Reputation: 1201
No need to escape # in sed, because it has no special meaning in an RE.
The \< and \> are left and right "word boundaries" in many sed versions. But it is not much standardized, so it is not clear if a # is a word character or a non-word character.
Perhaps you can use the line start/end anchors instead
Code:
sed -i 's/^#will$/will/' sample.txt
Code:
sed -i '/^#will$/ s/.//' sample.txt
The /g option is pointless (trying multiple substitutions per line).

Last edited by MadeInGermany; 06-26-2017 at 09:20 AM. Reason: Added sed -i option, removed the s too many
 
  


Reply

Tags
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 for a string, duplicate original and replace the string Jykke Programming 17 06-29-2016 10:14 AM
sed: search for string, then match and replace the next occurance of a word nbritton Programming 4 01-21-2015 12:40 PM
[SOLVED] search and replace string with special character perl or sed. Noobux Programming 4 05-21-2012 03:16 PM
[SOLVED] sed: global search and replace if a string isn't anywhere in that line linux_kung_fu Linux - General 5 03-09-2012 10:53 AM

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

All times are GMT -5. The time now is 01:27 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