Replacing string characters using CLI

0 votes

I want to replace a few characters in a string. For eg. say replace all x,y,z with c in aabbxxddeeyyzzkk.

I know it can be done using

$string" | tr 'x' 'c' | tr 'y' 'c'

But I want some way to do this without using pipes.

Jun 11 in Linux Administration by Atul
• 10,220 points

edited Jun 11 by Atul 10 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

To replace each of xy and z with c use:

echo "$string" | tr xyz c

in order to replace the repeating occurrences with a single c use:

echo "$string" | sed -r 's/[xyz]+/c/g'

answered Jun 11 by DareDev
• 6,670 points

Related Questions In Linux Administration

0 votes
1 answer

How to remove brackets using sed?

Try this: sed 's/[()]//g' <<< Hi(hello).How are you? READ MORE

answered Feb 12 in Linux Administration by Omkar
• 66,910 points
24 views
0 votes
1 answer

how to loop through the content of a file using bash

One of the ways to do it ...READ MORE

answered Feb 15 in Linux Administration by ajs3033
• 7,080 points
50 views
0 votes
1 answer

Downloading file using SSH from a server without web access

Run this command in  your terminal: scp your_username@remotehost.edu:foobar.txt ...READ MORE

answered Mar 5 in Linux Administration by ajs3033
• 7,080 points
24 views
0 votes
1 answer

redirecting stdout and stderr to file using bash

cmd >>file.txt 2>&1 Bash always executes and redirects ...READ MORE

answered Mar 19 in Linux Administration by ajs3033
• 7,080 points
18 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How do I set variable if a specific package version is installed in CFEngine?

Here is what you can do.Just use packagesmatching to ...READ MORE

answered Jul 12, 2018 in Other DevOps Questions by Atul
• 10,220 points
60 views
0 votes
2 answers

How do I find all files containing specific text on Linux?

grep -rnw 'text to find recursively inside ...READ MORE

answered May 20 in Linux Administration by Ritesh Singh
2,077 views
0 votes
1 answer

How to perform proxy http request using curl?

One of the ways is: export http_proxy=http://your.proxy.server:port/ Then you ...READ MORE

answered Mar 26 in Linux Administration by DareDev
• 6,670 points
22 views
0 votes
1 answer

Access Denied to user root@localhost while using mysql

For MySQL versions < 5.7: the default root ...READ MORE

answered May 13 in Linux Administration by DareDev
• 6,670 points
22 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.