How to replace special characters?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to replace special characters?
# 15  
Old 10-31-2012
Code:
$ seq -f "%03g" 0 400 | while read i; do echo -e "code $i : \0$i"; done | cat -v | grep 'M-^E'
code 205 : M-^E

Looking especially for those having long sequences and filtering out those that are ending with figures:

Code:
$ seq -f "%03g" 0 400 | while read i; do echo -e "code $i : \0$i"; done | cat -v | awk 'length($0)>12&&$0!~/.*[0-9]+$/' | pr -5 -s'  ' -t
code 000 : ^@    code 177 : ^?    code 235 : M-^]    code 305 : M-E    code 343 : M-c
code 001 : ^A    code 200 : M-^@    code 236 : M-^^    code 306 : M-F    code 344 : M-d
code 002 : ^B    code 201 : M-^A    code 237 : M-^_    code 307 : M-G    code 345 : M-e
code 003 : ^C    code 202 : M-^B    code 240 : M-     code 310 : M-H    code 346 : M-f
code 004 : ^D    code 203 : M-^C    code 241 : M-!    code 311 : M-I    code 347 : M-g
code 005 : ^E    code 204 : M-^D    code 242 : M-"    code 312 : M-J    code 350 : M-h
code 006 : ^F    code 205 : M-^E    code 243 : M-#    code 313 : M-K    code 351 : M-i
code 007 : ^G    code 206 : M-^F    code 244 : M-$    code 314 : M-L    code 352 : M-j
code 010 : ^H    code 207 : M-^G    code 245 : M-%    code 315 : M-M    code 353 : M-k
code 013 : ^K    code 210 : M-^H    code 246 : M-&    code 316 : M-N    code 354 : M-l
code 014 : ^L    code 211 : M-^I    code 247 : M-'    code 317 : M-O    code 355 : M-m
code 015 : ^M    code 212 : M-^J    code 250 : M-(    code 320 : M-P    code 356 : M-n
code 016 : ^N    code 213 : M-^K    code 251 : M-)    code 321 : M-Q    code 357 : M-o
code 017 : ^O    code 214 : M-^L    code 252 : M-*    code 322 : M-R    code 360 : M-p
code 020 : ^P    code 215 : M-^M    code 253 : M-+    code 323 : M-S    code 361 : M-q
code 021 : ^Q    code 216 : M-^N    code 254 : M-,    code 324 : M-T    code 362 : M-r
code 022 : ^R    code 217 : M-^O    code 255 : M--    code 325 : M-U    code 363 : M-s
code 023 : ^S    code 220 : M-^P    code 256 : M-.    code 326 : M-V    code 364 : M-t
code 024 : ^T    code 221 : M-^Q    code 257 : M-/    code 327 : M-W    code 365 : M-u
code 025 : ^U    code 222 : M-^R    code 272 : M-:    code 330 : M-X    code 366 : M-v
code 026 : ^V    code 223 : M-^S    code 273 : M-;    code 331 : M-Y    code 367 : M-w
code 027 : ^W    code 224 : M-^T    code 274 : M-<    code 332 : M-Z    code 370 : M-x
code 030 : ^X    code 225 : M-^U    code 275 : M-=    code 333 : M-[    code 371 : M-y
code 031 : ^Y    code 226 : M-^V    code 276 : M->    code 334 : M-\    code 372 : M-z
code 032 : ^Z    code 227 : M-^W    code 277 : M-?    code 335 : M-]    code 373 : M-{
code 033 : ^[    code 230 : M-^X    code 300 : M-@    code 336 : M-^    code 374 : M-|
code 034 : ^\    code 231 : M-^Y    code 301 : M-A    code 337 : M-_    code 375 : M-}
code 035 : ^]    code 232 : M-^Z    code 302 : M-B    code 340 : M-`    code 376 : M-~
code 036 : ^^    code 233 : M-^[    code 303 : M-C    code 341 : M-a    code 377 : M-^?
code 037 : ^_    code 234 : M-^\    code 304 : M-D    code 342 : M-b    code 400 : ^@


Last edited by ctsgnb; 10-31-2012 at 02:06 PM..
# 16  
Old 10-31-2012
Quote:
Originally Posted by ctsgnb
Code:
$ seq -f "%03g" 0 400 | while read i; do echo -e "code $i : \0$i"; done | cat -v | grep 'M-^E'
code 205 : M-^E


Thanks for your reply. one thing I need to know how I can find the ascii character for code 205.

Thanks in advance
ken002
# 17  
Old 10-31-2012
did you try :

Code:
echo -e '\0205'

Code:
echo -e '\0205' | od -bc

?
# 18  
Old 11-04-2012
Quote:
Originally Posted by ctsgnb
Code:
$ seq -f "%03g" 0 400 | while read i; do echo -e "code $i : \0$i"; done | cat -v | grep 'M-^E'
code 205 : M-^E

Looking especially for those having long sequences and filtering out those that are ending with figures:

Code:
$ seq -f "%03g" 0 400 | while read i; do echo -e "code $i : \0$i"; done | cat -v | awk 'length($0)>12&&$0!~/.*[0-9]+$/' | pr -5 -s'  ' -t
code 000 : ^@    code 177 : ^?    code 235 : M-^]    code 305 : M-E    code 343 : M-c
code 001 : ^A    code 200 : M-^@    code 236 : M-^^    code 306 : M-F    code 344 : M-d
code 002 : ^B    code 201 : M-^A    code 237 : M-^_    code 307 : M-G    code 345 : M-e
code 003 : ^C    code 202 : M-^B    code 240 : M-     code 310 : M-H    code 346 : M-f
code 004 : ^D    code 203 : M-^C    code 241 : M-!    code 311 : M-I    code 347 : M-g
code 005 : ^E    code 204 : M-^D    code 242 : M-"    code 312 : M-J    code 350 : M-h
code 006 : ^F    code 205 : M-^E    code 243 : M-#    code 313 : M-K    code 351 : M-i
code 007 : ^G    code 206 : M-^F    code 244 : M-$    code 314 : M-L    code 352 : M-j
code 010 : ^H    code 207 : M-^G    code 245 : M-%    code 315 : M-M    code 353 : M-k
code 013 : ^K    code 210 : M-^H    code 246 : M-&    code 316 : M-N    code 354 : M-l
code 014 : ^L    code 211 : M-^I    code 247 : M-'    code 317 : M-O    code 355 : M-m
code 015 : ^M    code 212 : M-^J    code 250 : M-(    code 320 : M-P    code 356 : M-n
code 016 : ^N    code 213 : M-^K    code 251 : M-)    code 321 : M-Q    code 357 : M-o
code 017 : ^O    code 214 : M-^L    code 252 : M-*    code 322 : M-R    code 360 : M-p
code 020 : ^P    code 215 : M-^M    code 253 : M-+    code 323 : M-S    code 361 : M-q
code 021 : ^Q    code 216 : M-^N    code 254 : M-,    code 324 : M-T    code 362 : M-r
code 022 : ^R    code 217 : M-^O    code 255 : M--    code 325 : M-U    code 363 : M-s
code 023 : ^S    code 220 : M-^P    code 256 : M-.    code 326 : M-V    code 364 : M-t
code 024 : ^T    code 221 : M-^Q    code 257 : M-/    code 327 : M-W    code 365 : M-u
code 025 : ^U    code 222 : M-^R    code 272 : M-:    code 330 : M-X    code 366 : M-v
code 026 : ^V    code 223 : M-^S    code 273 : M-;    code 331 : M-Y    code 367 : M-w
code 027 : ^W    code 224 : M-^T    code 274 : M-<    code 332 : M-Z    code 370 : M-x
code 030 : ^X    code 225 : M-^U    code 275 : M-=    code 333 : M-[    code 371 : M-y
code 031 : ^Y    code 226 : M-^V    code 276 : M->    code 334 : M-\    code 372 : M-z
code 032 : ^Z    code 227 : M-^W    code 277 : M-?    code 335 : M-]    code 373 : M-{
code 033 : ^[    code 230 : M-^X    code 300 : M-@    code 336 : M-^    code 374 : M-|
code 034 : ^\    code 231 : M-^Y    code 301 : M-A    code 337 : M-_    code 375 : M-}
code 035 : ^]    code 232 : M-^Z    code 302 : M-B    code 340 : M-`    code 376 : M-~
code 036 : ^^    code 233 : M-^[    code 303 : M-C    code 341 : M-a    code 377 : M-^?
code 037 : ^_    code 234 : M-^\    code 304 : M-D    code 342 : M-b    code 400 : ^@

Hi, ctsgnb,

I put filter condition chr(13), it removed ^M, but M-^E is still there , I put filter condition chr(133) (I found a char it shows octal code 205 match ascii code 133), but for somehow it doesn't work. do you have any idea which value or what kind of charactor I need to put in to filter out M-^E. I need remove these charactor in another process before generating the file.

Thanks in advance

Smilie

Last edited by ken002; 11-04-2012 at 09:19 AM..
ken002
# 19  
Old 11-04-2012
did you try :

Code:
tr -d '\205' <yourfile >yourfile.fixed

?
# 20  
Old 11-04-2012
Did you try strings infile ?
# 21  
Old 11-04-2012
Quote:
Originally Posted by ctsgnb
did you try :

Code:
tr -d '\205' <yourfile >yourfile.fixed

?
I tried this code and got following:

Code:
 
$ echo -e '\0205' | od -bc
0000000 205 012
        205  \n
0000002

I am really new for unix, so I can not understand ths result, would you please explain this result for me.

many thanks

Smilie
ken002
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Replace Pattern with another that has Special Characters

Hello Team, Any help would be much appreciated for the below scenario: I have a sed command below where I am trying to replace the contents of 'old_pkey' variable with 'new_pkey' variable in a Soap request file (delete_request.txt). This works fine for regular string values, but this new_pkey... (8 Replies)
Discussion started by: ChicagoBlues
8 Replies

2. UNIX for Advanced & Expert Users

How to replace special characters?

Hi Team, I have data like this. |*|.5|*|0.2|*|A.B|*| Would like to add zero (0) before the decimal point where there is no zero as |*|0.5|*|0.2|*|A.B|*| How to replace |*|. with |*|0. I tried below command which didn't work echo '|*|.5|*|0.2|*|A.B|*' | sed... (4 Replies)
Discussion started by: Ravi.K
4 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

Replace special characters with backslash and character

Hi, I have a string wherein i need to replace special characters with backslash and that character. Ex: If my string is a=qwerty123@!, then the new string should be a_new=qwerty123\@\!\, Thanks (3 Replies)
Discussion started by: temp_user
3 Replies

5. Shell Programming and Scripting

Replace special characters with Escape characters?

i need to replace the any special characters with escape characters like below. test!=123-> test\!\=123 !@#$%^&*()-= to be replaced by \!\@\#\$\%\^\&\*\(\)\-\= (8 Replies)
Discussion started by: laknar
8 Replies

6. Shell Programming and Scripting

Replace special characters

I have a line ending with special character and 0 The special character is the field separator for this line in VI mode the file will look like below, but while cat the special character wont display i know the hexa code for the special character ^_ is \x1f and ascii code is \0037, ... (0 Replies)
Discussion started by: ratheeshjulk
0 Replies

7. Solaris

How to replace special characters in vi?

Hi , I want to replace the special characters in the file. For eg: cat abc 1234/4455/acb 234/k/lll/ 234`fs`fd I want to replace / and ` with the letter a and the output should like below. How to achieve this. 1234a4455aacb 234akallla 234afsafd (2 Replies)
Discussion started by: rogerben
2 Replies

8. Shell Programming and Scripting

Using sed to replace special characters

Hi everyone I have file1 contains: '7832' ' 8765 6543 I want a sed command that will format as: '7832' , '8765' , '6543' I tried sed -e s/\'//g -e 's/^*//;s/*$//' file1 > file2 sed -e :a -e '$!N; s/\n/ /; ta' file2 which gives: 7832 8765 6543 I need some help to continue with... (5 Replies)
Discussion started by: nimo
5 Replies

9. UNIX for Dummies Questions & Answers

Find and replace special characters in a file

HI All I need a shell script ehich removes all special characters from file and converts the file to UTF-* format Specail characters to be removed must be configurable. strIllegal = @"?/><,:;""'{|\\+=-)(*&^%$#@!~`"; Please help me in getting this script as my scripting skilla are... (2 Replies)
Discussion started by: sujithchandra
2 Replies

10. UNIX for Dummies Questions & Answers

Replace Special characters in a file

Hi, I have a data like this in a file, 402003279034002000100147626030003300010000000000002000029000000 ær^M^\MÍW^H I need to replace those special char to some other char like # or $ Is there any ways to do it... I tried commands tr,sed and many but it was not able to replace because... (1 Reply)
Discussion started by: solai
1 Replies
Login or Register to Ask a Question