Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 06-25-2017, 02:38 PM   #16
Registered: Jan 2017
Location: Manhattan, NYC NY
Distribution: Mac OS X, iOS, Solaris
Posts: 508

Rep: Reputation: 143Reputation: 143

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
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_12{.0|.1}
Posts: 5,581
Blog Entries: 11

Rep: Reputation: 3596Reputation: 3596Reputation: 3596Reputation: 3596Reputation: 3596Reputation: 3596Reputation: 3596Reputation: 3596Reputation: 3596Reputation: 3596Reputation: 3596
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
Senior Member
Registered: Dec 2011
Location: Simplicity
Posts: 1,675

Rep: Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755Reputation: 755
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
sed -i 's/^#will$/will/' sample.txt
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



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
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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:10 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
Open Source Consulting | Domain Registration