Replace characters in a string using their ascii value


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace characters in a string using their ascii value
# 1  
Old 03-03-2005
Replace characters in a string using their ascii value

Hi All,

In the HP Unix that i'm using when i initialise a string as Stalled="'30¬G'"
Stalled=$Stalled" '30¬C'", it is taking the character ¬ as a comma. I need to grep for 30¬G 30¬C in a file and take its count. But since this character ¬ is not being understood, the count returns a zero.
The ascii value of the character ¬ is 188.
I thought of replacing all occurrences of comma using something like
chr(188). But i dont know how to.
Could some one help me or give me some other idea to go about this. I need to do this urgently :-(
Thanks in advance...
# 2  
Old 03-03-2005
Quote:
Originally Posted by roops
Hi All,

In the HP Unix that i'm using when i initialise a string as Stalled="'30¬G'"
Stalled=$Stalled" '30¬C'", it is taking the character ¬ as a comma. I need to grep for 30¬G 30¬C in a file and take its count. But since this character ¬ is not being understood, the count returns a zero.
The ascii value of the character ¬ is 188.
I thought of replacing all occurrences of comma using something like
chr(188). But i dont know how to.
Could some one help me or give me some other idea to go about this. I need to do this urgently :-(
Thanks in advance...
tr '\188' ',' < file

Last edited by vgersh99; 03-03-2005 at 10:05 AM..
# 3  
Old 03-04-2005
Hi vgersh99

Thank u very much for the pointer u gave. But i cracked this problem using grep itself. I said in 30¬G, let the 3rd character(each record in the file starts with 30¬G or 30¬C ) be anything other than zero (since in the file it is alwz ¬ and never zero.) and the fourth character shud be [GC]. From the grep, i got the count..

Thanks anyways coz i learnt what "tr" command is all about. I'm new to unix and my work revolves around unix. So i'm learning Unix while i'm working on live problems. :-)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace alphabets in a string with their ASCII values

hi. I have a requirement where I need to REPLACE all alphabets from an alphanumeric input string into their respective ASCII decimal value. For example: If the input string is ABAC123, the output should be 65666567123 I am seeking a single line command, and I was trying searching for options... (21 Replies)
Discussion started by: kumarjt
21 Replies

2. Shell Programming and Scripting

Convert UTF-8 file to ASCII/ISO8859-1 OR replace characters

I am trying to develop a script which will work on a source UTF-8 file and perform one or more of the following It will accept the target encoding as an argument e.g. US-ASCII or ISO-8859-1, etc 1. It should replace all occurrences of characters outside target character set by " " (space) or... (3 Replies)
Discussion started by: hemkiran.s
3 Replies

3. Shell Programming and Scripting

Help to replace the string with special characters

{"name":"alR_pl-ENVIRONMENT_192_168_211_123_sDK_PROVISION_7","description":"aLR_pl-ENVIRONMENT_192_168_211_123_sDK_PROVISION_7","json_class":"Chef::Role","default_attributes":{},"override_attributes":{"yoapp":{"jboss":"5.1.0","port":"2243","warname":"soap","datacenter":"alR","ip":"192.168.211.123","... (3 Replies)
Discussion started by: nikhil jain
3 Replies

4. Shell Programming and Scripting

Find/replace alpha characters in string

Hi, I would like to find a 3-letter character series in a string/variable and replace it with x's. An example set of strings is: 563MS333_101_afp_400-100_screening 563MS333_104-525_rjk_525_screening 563MS333_110_dlj_500-100_w24 563MS333_888-100_mmm_424_screening The only constants... (5 Replies)
Discussion started by: goodbenito
5 Replies

5. Shell Programming and Scripting

Search and Replace Extended Ascii Characters

We are getting extended Ascii characters in the input file and my requirement is to search and replace them with a space. I am using the following command LANG=C sed -e 's// /g' It is doing a good job, but in some cases it is replacing the extended characters with two spaces. So my input... (12 Replies)
Discussion started by: ysvsr1
12 Replies

6. Shell Programming and Scripting

search and replace characters in one string

I have lines like: Dog Cat House Mouse Dog Cat House Mouse Dog Cat House Mouse Dog Cat House Mouse I'd like to replace characters only in $3. H -> Z s -> W e -> x Resulting in something like (where $1, $2, and $4 are not changed): Dog Cat ZouWx Mouse Dog Cat ZouWx Mouse... (3 Replies)
Discussion started by: dcfargo
3 Replies

7. Shell Programming and Scripting

convert ascii values into ascii characters

Hi gurus, I have a file in unix with ascii values. I need to convert all the ascii values in the file to ascii characters. File contains nearly 20000 records with ascii values. (10 Replies)
Discussion started by: sandeeppvk
10 Replies

8. Shell Programming and Scripting

read in a file character by character - replace any unknown ASCII characters with spa

Can someone help me to write a script / command to read in a file, character by character, replace any unknown ASCII characters with space. then write out the file to a new filename/ Thanks! (1 Reply)
Discussion started by: raghav525
1 Replies

9. UNIX for Dummies Questions & Answers

Help with find and replace w/string containing special characters

Can I get some help on this please, I have looked at the many post with similar questions and have tried the solutions and they are not working for my scenario which is: I have a text file (myfile) that contains b_log=$g_log/FILENAME.log echo "Begin processing file FILENAME " >> $b_log ... (4 Replies)
Discussion started by: CAGIRL
4 Replies

10. Shell Programming and Scripting

Replace string and delete extra characters

Hopefully someone can help out here. This is probably fairly basic, but I've searched and tried several variations of the solutions presented in these forums, so I'll go ahead and ask. How can I locate a string in a file, delete the characters after the string and then replace the string with a... (2 Replies)
Discussion started by: slaubhan
2 Replies
Login or Register to Ask a Question