replacing specific characters in a string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting replacing specific characters in a string
# 1  
Old 08-20-2008
replacing specific characters in a string

Hi Friends,

Following is an output of a script

OPWQERIUTYKLSADFJHGXZNMCVBWQOPERIUTYKLSADFJHGXZNMCVB

I want to replace above string's 11 to 17 character by ******* (7 stars)
How can it be done?
Please somebody guide me.
# 2  
Old 08-20-2008
try:
Code:
echo -n `echo $str | cut -c 1-10` ; echo -n '*******' ; echo $str | cut -c 18-

# 3  
Old 08-20-2008
You can use like this

$ a='OPWQERIUTYKLSADFJHGXZNMCVBWQOPERIUTYKLSADFJHGXZNMCVB'

$ echo $a | awk '{line=substr($0, 11,7);sub(line,"*******",$0);print $0; }'
# 4  
Old 08-20-2008
great manoj!
# 5  
Old 08-20-2008
And another way:

Code:
echo $a | sed 's/^\(.\{10\}\).\{7\}/\1*******/'

# 6  
Old 08-20-2008
Thank you very very much Yogesh & Manoj.. both the suggestions are perfectly working.
Thank you once again
Bye & take care
# 7  
Old 08-20-2008
Code:
echo OPWQERIUTYKLSADFJHGXZNMCVBWQOPERIUTYKLSADFJHGXZNMCVB |
sed 's/\(.\{1,10\}\)\(.\{1,7\}\)\(.*\)/\1*****\3/'> sed 's/\(.\{1,10\}\)\(.\{1,5\}\)\(.*\)/\1*****\3/'

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Outputting characters after a given string and reporting the characters in the row below --sed

I have this fastq file: @M04961:22:000000000-B5VGJ:1:1101:9280:7106 1:N:0:86 GGGGGGGGGGGGCATGAAAACATACAAACCGTCTTTCCAGAAATTGTTCCAAGTATCGGCAACAGCTTTATCAATACCATGAAAAATATCAACCACACCA +test-1 GGGGGGGGGGGGGGGGGCCGGGGGFF,EDFFGEDFG,@DGGCGGEGGG7DCGGGF68CGFFFGGGG@CGDGFFDFEFEFF:30CGAFFDFEFF8CAF;;8... (10 Replies)
Discussion started by: Xterra
10 Replies

2. Shell Programming and Scripting

How to test that a string doesn't contain specific characters?

Hi ! :) I made this : #!/bin/bash rsa_dir="/etc/openvpn/easy-rsa/" rsa_key_dir="/etc/openvpn/easy-rsa/keys/" ccd_dir="/etc/openvpn/ccd/" regex_special_char='' cd $rsa_dir while read -p "Please can you enter the vpn's username : " username ] || ] || ] || ] do echo "Your entry... (10 Replies)
Discussion started by: Arnaudh78
10 Replies

3. UNIX for Beginners Questions & Answers

Replacing string/special characters using a 'conversion' table

Hi, Does anyone know if there is a script or program available out there that uses a conversion table to replace special characters from a file? I am trying to remove some special characters from a file but there are several unprintable/control characters that some I need to remove but some I... (2 Replies)
Discussion started by: newbie_01
2 Replies

4. Shell Programming and Scripting

Replacing whole string starting with specific works

Hi guys, So what I am trying to accomplish is to replace a whole string starting with some designated string. eg: When even I find a string starting with : eai.endpoint.url= replace the entire line with: eai.endpoint.url=http://www.endpoint.com/API Righ now I am trying to... (4 Replies)
Discussion started by: Junaid Subhani
4 Replies

5. Shell Programming and Scripting

Replacing specific characters using sed

Hi, I have a text file which is output from a server and it lists all the files in a specific volume. However, the volume name appears as volume_name:. I would like to replace this with \\volume_name\volume_name. This is not a problem in itself as I can use sed to globally look for the... (8 Replies)
Discussion started by: vnayak
8 Replies

6. Shell Programming and Scripting

Count specific characters at specific column positions

Hi all, I need help. I have an input text file (input.txt) like this: 21 GTGCAACACCGTCTTGAGAGG 50 21 GACCGAGACAGAATGAAAATC 73 21 CGGGTCTGTAGTAGCAAACGC 108 21 CGAAAAATGAACCCCTTTATC 220 21 CGTGATCCTGTTGAAGGGTCG 259 Now I need to count A/T/G/C numbers at each character location in column... (2 Replies)
Discussion started by: thienxho
2 Replies

7. Shell Programming and Scripting

Can't figure out how to find specific characters in specific columns

I am trying to find a specific set of characters in a long file. I only want to find the characters in column 265 for 4 bytes. Is there a search for that? I tried cut but couldn't get it to work. Ex. I want to find '9999' in column 265 for 4 bytes. If it is in there, I want it to print... (12 Replies)
Discussion started by: Drenhead
12 Replies

8. Shell Programming and Scripting

sed replacing specific characters and control characters by escaping

sed -e "s// /g" old.txt > new.txt While I do know some control characters need to be escaped, can normal characters also be escaped and still work the same way? Basically I do not know all control characters that have a special meaning, for example, ?, ., % have a meaning and have to be escaped... (11 Replies)
Discussion started by: ijustneeda
11 Replies

9. Shell Programming and Scripting

Replacing string with special characters in shell

Hi, I am trying to replace a string in shell but it is not working correctly. @xcom.file@ needs to be replaced with tb137 Plz help.Thx. Please use and tags when posting code, data or logs etc. to preserve formatting and enhance readability, thanks. (4 Replies)
Discussion started by: manish72
4 Replies

10. UNIX for Dummies Questions & Answers

replacing string in a column on a specific line

hi, i currently have a file with columns similar to this customer name owed CID123 John 300 CID342 harry 500 at present i use use awk to find the amount owed by the customer using the customer ID (CID). if the customer spends more money how would i go about using sed/awk etc to... (2 Replies)
Discussion started by: skinnygav
2 Replies
Login or Register to Ask a Question