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, 2019 in Linux Administration by Atul
• 10,240 points

edited Jun 11, 2019 by Atul 86 views

1 answer to this question.

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, 2019 by DareDev
• 6,870 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, 2019 in Linux Administration by Omkar
• 69,030 points
408 views
0 votes
2 answers

how to loop through the content of a file using bash

#!/bin/bash for i in  `cat peptides.txt` do echo $i done READ MORE

answered Sep 4 in Linux Administration by Prakash K. Aithal
800 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, 2019 in Linux Administration by ajs3033
• 7,280 points
107 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, 2019 in Linux Administration by ajs3033
• 7,280 points
783 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,240 points
206 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, 2019 in Linux Administration by Ritesh Singh
13,762 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, 2019 in Linux Administration by DareDev
• 6,870 points
2,243 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, 2019 in Linux Administration by DareDev
• 6,870 points
1,931 views