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 04-14-2023, 05:15 PM   #16
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,152

Rep: Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125

Personally I prefer [^[:space:]] in this context but the effect is likely the same. There is also no requirement for the capture group, & suffices. One-liners are often unnecessarily disparaged.
 
1 members found this post helpful.
Old 04-15-2023, 10:43 AM   #17
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Quote:
Originally Posted by syg00 View Post
Personally I prefer [^[:space:]] in this context but the effect is likely the same. ...
I tried this and it works.

Quote:
There is also no requirement for the capture group, & suffices.
I tried this and couldn't make it work. Please post working code.

Quote:
One-liners are often unnecessarily disparaged.
I like one-liners. If concise code is difficult to read it should be commented.

Daniel B. Martin

.
 
Old 04-15-2023, 12:50 PM   #18
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,249

Rep: Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323Reputation: 5323
I agree with the people who said to use sed. If you used Python, you'd just do the same regular-expression search-and-replace that you'd do in sed.

Code:
❯ echo "left -21 exMAX_14" | sed -E 's/(\b\w*MAX\w*\b)/\1_33/'
left -21 exMAX_14_33
 
Old 04-15-2023, 01:41 PM   #19
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Quote:
Originally Posted by dugan View Post
I agree with the people who said to use sed. ...
Code:
sed -E 's/(\b\w*MAX\w*\b)/\1_33/'
I tried this and couldn't make it work. With this minor modification it does work.
Code:
sed -E 's/(\b\w*MAX\w*\b)/\1_33/g'
Daniel B. Martin

.

Last edited by danielbmartin; 04-15-2023 at 01:47 PM. Reason: Cosmetic improvement
 
Old 04-15-2023, 03:01 PM   #20
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,832

Rep: Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218Reputation: 1218
Example with & (reference to all captured)
Code:
sed 's/MAX[[:graph:]]*/&_33/g' $InFile >$OutFile
 
1 members found this post helpful.
Old 04-16-2023, 12:47 PM   #21
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,881

Rep: Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660Reputation: 660
Quote:
Originally Posted by MadeInGermany View Post
Example with & (reference to all captured)
Code:
sed 's/MAX[[:graph:]]*/&_33/g' $InFile >$OutFile
This solution wins a prize for being concise and readable!

Daniel B. Martin

.
 
Old 04-18-2023, 02:41 PM   #22
sharky
Member
 
Registered: Oct 2002
Posts: 569

Original Poster
Rep: Reputation: 84
Forgot to thank everyone for the help.

Thanks very much to all.
 
  


Reply



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
[SOLVED] Bash command to 'cut' text into another text file & modifying text. velgasius Programming 4 10-17-2011 04:55 AM
Firefox problem with text boxes automatically highlighting text loki993 Linux - Software 2 07-16-2010 01:52 PM
xmllint munging UTF8 chars in HTML document... workaround? mattp52 Programming 0 01-12-2009 01:08 AM
How to parse text file to a set text column width and output to new text file? jsstevenson Programming 12 04-23-2008 02:36 PM
More text in Text Mode LandRoverMan Linux - Newbie 2 06-10-2003 11:47 AM

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

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