LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-06-2022, 11:23 AM   #1
kzo81
Member
 
Registered: Aug 2014
Location: Hungary
Distribution: Debian, Linux Mint, CentOS
Posts: 197

Rep: Reputation: Disabled
sed Q


Hi,

I'd like to change red string with sed, but I couldn figure out in the afternoon:

WT-Client AaaabbBbbbb (172.10.10.1)
WT-Client X (172.10.10.1)

I was trying this:
Code:
echo "WT-Client AaaabbBbbbb (172.10.10.1)" | sed 's/^WT-Client.\w.($/WT-Client X/g'
Could you please help me?
 
Old 01-06-2022, 11:33 AM   #2
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,294
Blog Entries: 3

Rep: Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719Reputation: 3719
You're very close. Use the -r option to adjust the type of regex rules Sed is expecting. You have written an Extended Regular Expression and Sed needs to know that:

Code:
sed -r -e 's/^(WT-Client) \w+/\1 X/'
You can also look at AWK:

Code:
echo "WT-Client AaaabbBbbbb (172.10.10.1)" | awk '$1~/^WT-Client/ {$2 = "X"; print}'
 
1 members found this post helpful.
Old 01-06-2022, 11:34 AM   #3
kzo81
Member
 
Registered: Aug 2014
Location: Hungary
Distribution: Debian, Linux Mint, CentOS
Posts: 197

Original Poster
Rep: Reputation: Disabled
Thank you
 
Old 01-06-2022, 11:53 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,803

Rep: Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306Reputation: 7306
without -r:
Code:
echo "WT-Client AaaabbBbbbb (172.10.10.1)" | sed 's/^WT-Client.\w*.(/WT-Client X (/g'
 
1 members found this post helpful.
Old 01-06-2022, 01:59 PM   #5
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Without /g
Code:
echo "WT-Client AaaabbBbbbb (172.10.10.1)" |
sed '/^WT-Client/s/ \w*/ X/'
 
  


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
How do you do sed 's/anytext/'/g' or sed 's/anytext/\'/g' pppaaarrrkkk Programming 4 02-29-2008 12:15 PM
bash script with grep and sed: sed getting filenames from grep odysseus.lost Programming 1 07-17-2006 11:36 AM
[sed] "Advanced" sed question(s) G00fy Programming 2 03-20-2006 12:34 AM
sed and escaping & in something like: echo $y | sed 's/&/_/g' prx Programming 7 02-03-2005 11:00 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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