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
# 15  
Old 08-20-2014
Hi Robin,

By typo missed the data in between. The expectation of your's is correct, could you please provide the logic how would you processed the data and got the result. The file got generated by VB script.

Thanks,
Dines
# 16  
Old 08-20-2014
It was read by eye and converted by brain to hopefully confirm that we are working on the correct input to output relationship, hence why CODE tags are so important. I have done no coding so far.

Is the special character always the same? Can you confirm what character it is with od? If you can cut down a copy of the file to just contain the character, then use:-
Code:
od -x input_file

and paste the output here in [CODE] & [/CODE] tags, then that would help.


Is this a large file that needs the powerful processing of awk, sed or perl, or would a simpler, but slower loop in a shell be acceptable? If the file is smaller , but there are many than you want to call in a loop, sometimes calling awk etc. can work out slower.



Robin
# 17  
Old 08-20-2014
Hi,

Find the below output for the above command. File size would be greater than 1 MB.

Code:
0000000 314d 4847 3139 3620 3720 4942 4d35 3133
0000020 414d 4d4f 44e2 9692 3037 2069 626d 7978
0000040 3636 6d63 7030 30e2 9692 3036 2033 3032
0000060 3631 39e2 9692 3141 2030 3030 3035 3031
0000100 3430 3732 3630 3533 3331 3630 30e2 9692
0000120 3041 2039 3830 e296 9233 3220 3230 3134
0000140 3037 3236 3035 3333 3136 30e2 9692 3134
0000160 2032 5452 4732 3132 2037 2039 38e2 9692
0000200 3039 2033 5020 5041 5554 4f20 464d 4742
0000220 4e20 2049 424d 3531 3341 4d4d 4f41 4d45
0000240 5249 4341 4e20 4d4f 4445 520a 4e20 494e
0000260 5355 5241 4e43 4533 3032 3631 39e2 9692
0000300 3430 2039 3738 3731 3430 3732 3539 3738
0000320 3720 2020 2031 3430 3732 3420 4e42 53e2
0000340 9692 3139 2041 3230 3134 3037 3235 3230
0000360 3134 3037 3234 200a
0000370

Thanks,
Dines
# 18  
Old 08-20-2014
Huh?

I was expecting to see just a single line with the character code for ú and a terminating 0a

I don't see a match for the rest of your sample either. Smilie I was looking for hex strings like this:-
Code:
0000000 4142 4344 3137 3220 3220 4231 3030 3031

The next character would be the ú that we're interested in. I don't fancy working out byte-for-byte what there is and what's which.
The above is from your first line up to the ú

Can you clarify which input you have used for this? If you have to sanitise the input, please provide the matching output for the sanitised version.



Thanks,
Robin
# 19  
Old 08-20-2014
Hi,

Find the below one.
Code:
0000000 4142 4344 3137 3220 3220 4231 3030 3031
0000020 c3ba 3045 2046 c3ba 3038 2044 696e 6573
0000040 6847 c3ba 3134 204b 756d 6172 4e61 6b6b
0000060 61c3 ba30 4520 c3ba 3343 3f49 4ec3 ba31
0000100 343f 4546 4748 3334 300a
0000112

Thanks,
Dines

---------- Post updated at 08:05 AM ---------- Previous update was at 07:41 AM ----------

Hi Robin,

Could you please provide some information on the above.

Thanks,
Dines
This User Gave Thanks to dineshnak For This Post:
# 20  
Old 08-20-2014
Right, so hex character c3 is what we're after. Now that we have much of the information we need, it's time for a think.......



Robin
# 21  
Old 08-20-2014
Quote:
Originally Posted by rbatte1
Right, so hex character c3 is what we're after. Now that we have much of the information we need, it's time for a think.......



Robin
No. This is UTF8, the character you're looking for is the two byte character c3 ba.
Sometimes things like this are easier to see with od -cx as in:
Code:
echo "302619ú1A?"|od -cbx
0000000    3   0   2   6   1   9   ú  **   1   A   ?  \n                
          063 060 062 066 061 071 303 272 061 101 077 012                
             3033    3632    3931    bac3    4131    0a3f                
0000014


Last edited by Don Cragun; 08-20-2014 at 10:30 AM.. Reason: Add od -c output...
This User Gave Thanks to Don Cragun For This Post:
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