Replace Special Character With Next Present Byte


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace Special Character With Next Present Byte
# 1  
Old 08-20-2014
Replace Special Character With Next Present Byte

Hi,

First find the special character, from the special character take next two bytes convert the bytes to decimal and replace with next present byte of decimal value times.

E.g.
Code:
Input: 302619ú1A? 
Output: 302619(3 spaces for ú1A)??????????????????????????

Thanks,
Dines

Last edited by Don Cragun; 08-20-2014 at 06:14 AM.. Reason: Add CODE tags.
# 2  
Old 08-20-2014
Yes?

What have you done so far?
# 3  
Old 08-20-2014
Code:
$ perl -Mutf8 -E '$value="302619ú1A?";$value=~s/[^A-Za-z\s\d]([\da-fA-F]{2})(.)/sprintf("   %s", $2 x hex($1))/e; say $value;' -
302619   ??????????????????????????

# 4  
Old 08-20-2014
Hi,

The below code failed with below error
"Unrecognized switch: -E (-h will show valid options)."
Could you guide us to change the code to use it in SunOS.

Thanks,
Dines
# 5  
Old 08-20-2014
You're running an older version of Perl try the following:
Code:
$ perl -Mutf8 -e '$value="302619ú1A?";$value=~s/[^A-Za-z\s\d]([\da-fA-F]{2})(.)/sprintf("   %s", $2 x hex($1))/e; print "$value\n";' -
302619   ??????????????????????????

# 6  
Old 08-20-2014
Hi,

Thanks for you reply.
Could you please explain the process how to deal this in a file as multiple occurrence. eg:
Code:
IBM513AMMODú07 ibmyx66mcp00ú06 302619ú1A 00005014072605331600ú0A 980ú32 201407260533160ú14

Thanks,
Dines

Last edited by rbatte1; 08-20-2014 at 06:54 AM.. Reason: Added CODE tags
# 7  
Old 08-20-2014
Welcome dineshnak,
I don't really see the question clearly, but I have a few to questions pose in response first:-
  • Is this homework/assignment? There are specific forums for these.
  • What have you tried so far?
  • What output/errors do you get?
  • What OS and version are you using?
  • What are your preferred tools? (C, shell, perl, awk, etc.)
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)
Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.


We're all here to learn and getting the relevant information will help us all.


Regards,
Robin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. What is on Your Mind?

Merry Xmas (special present inside)

A Merry Xmas to all of you. And, as a special present to vbe (he knows why) a little exercise: #! /bin/ksh pPrintSnow () { typeset -i iLen=$1 while (( iLen )) ; do if ! (( RANDOM % 31 )) ; then printf "%1s" "." else printf "%1s" " " fi ((... (0 Replies)
Discussion started by: bakunin
0 Replies

2. 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

3. UNIX for Dummies Questions & Answers

Changing a special line and Byte in a random file

Hello I created 3 files by: dd if=/dev/urandom bs=1024 count=1000000 of=./testfile1 dd if=/dev/urandom bs=1024 count=5000000 of=./testfile2 dd if=/dev/urandom bs=1024 count=10000000 of=./testfile3 Now I want to know how to make a change in a specific byte and/or line of theses files? (2 Replies)
Discussion started by: frhling
2 Replies

4. Shell Programming and Scripting

[Solved] Find and replace till nth occurence of a special character

Hi, I have a requirement to search for a pattern in each line in a file and remove the in between words till the 3rd occurrence of double quote ("). Ex: CREATE TABLE "SCHEMANAME"."AMS_LTV_STATUS" (Note: "SCHEMANAME" may changes for different schemas. Its not a fixed value) I need to... (2 Replies)
Discussion started by: satyaatcgi
2 Replies

5. Shell Programming and Scripting

How to replace special character using sed?

How can I replace the follong text including to number 7000? cat tmp0.txt Winston (UK) Wong I would the 7000 to replace Winston (UK) Wong. I fail with method below: sed ' s /Winston\(UK\)Wong/7000 tmp0.txt' (1 Reply)
Discussion started by: vivien_chu
1 Replies

6. Shell Programming and Scripting

replace /n with special character

I would like to replace /n with ',' and after replace remove last semicolon then put a open brace in starting and closing brace in end of line. See below example: input: 1234 3455 24334 234 output: ('1234,'3455',24334','234') Thanks (3 Replies)
Discussion started by: anupdas
3 Replies

7. Shell Programming and Scripting

How to replace with a special character in String

Hi, I am beginner to Shell Scripting. I have a String like this "testabcdef", i need the first character as it is and the remaining character should be replaced by the the '*' character. e.g(t***********) PLZ Suggest me. (5 Replies)
Discussion started by: nanthagopal
5 Replies

8. Shell Programming and Scripting

cutting long text by special char around 100 byte and newline

Regard, How can i cut the text by special char(|) around 100 byte and write the other of the text at newline using Perl. ... (3 Replies)
Discussion started by: Shawn, Lee
3 Replies

9. Shell Programming and Scripting

how to replace the special character with another using SED

I have the replace the pattern in the file , ); to ); Could someone please help me to get this command. (2 Replies)
Discussion started by: mohan.bit
2 Replies

10. Shell Programming and Scripting

sed special character replace

I need to do the following: text in the format of: ADDRESS=abcd123:1111 - abcd123:1111 is different on every system. replace with: ADDRESS=localhost:2222 sed 's/ADDRESS=<What do I use here?>/ADDRESS=localhost:2222/g' Everything I've tried ends up with: ... (3 Replies)
Discussion started by: toor13
3 Replies
Login or Register to Ask a Question