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
# 8  
Old 08-20-2014
Hi Robin,
We are getting a fixed length file got compressed with special character "ú07 & ú1A?, etc.," in between the characters, need to read the special characters along with the next two bytes hexadecimal value. Once we read the hexadecimal value need to convert to decimal and add mentioned byte (symbol or space) after hexadecimal value in a file. We tried using awk, sed but no progress in output. we need some sample script or information to run the script on SunOS and drive further.

Thanks,
Dines
# 9  
Old 08-20-2014
Is this packed-decimal data from a mainframe perhaps? It would probably be easier to generate the file as truly plain text at the source before transferring it. If you are using FTP, make sure the transfer is forced to be an ASCII transfer.

From your example in the first post, I think what you want is to read the 1A? to mean 'please insert 26 (decimal) question marks' and any other time we hit the special character in the same line or any other line.

It makes it all a bit complex, hence why I suggest you generate a fully expanded file at the source. If it won't fit, or the transfer takes too long, then there are commercial compression tools that are available for pretty much any platform combination. We changed one transfer from 23 hours to 4 by using one, but there will be others out there.

What is your source system?



Robin
# 10  
Old 08-20-2014
Hi Robin,

We encounter fixed format special characters like "? or spaces" in the file between characters after hexadecimal values. The file got FTP from windows machine, provide some information how to handle the situtation using UNIX script.

Thanks,
Dines
# 11  
Old 08-20-2014
Is this a Windows compressed file, a Winzip file or something else?

It may be possible to expand this with gunzip or similar utilities if these are available to you, but we'd need to know how it is generated in the first place.


Robin
# 12  
Old 08-20-2014
The substitution regex above matches any character which is not a letter, number or space (as defined by the current locale) followed by 2 characters that could be interpreted as hexadecimal, followed by any character and replaces them with the 3 spaces followed by the character repeated n times.

The fact that Perl allows executable code in the substitution block means we can do things like this not available in sed or awk as a single substitution.

The e flag marks the substitution block for evaluation, the g flag would allow the substitution to be applied globally rather than to just the first match.

man perlre for more details on Perl regex
# 13  
Old 08-20-2014
Hi Robin,

File FTP from windows system without any compression, only data got compressed, we need to expand the data by finding the special character ie. "ú07 & ú1A?.," lies in the file and to pad the next byte ie(space or ?) after the hexadecimal value convert to decimal.

Sample Data:
Input Data:
Code:
ABCD172 2 B10001ú0E Fú08 DineshGú14 KumarNakkaú0E ú3C?INú14?EFGH340

Output Data:
Code:
ABCD172 2 B10001   (14 spaces) DineshG   (14 spaces) KumarNakka   (14 spaces)    ??????(60-?symbol)IN   ??????????????EFGH340

Thanks,
Dines

Moderator's Comments:
Mod Comment Please use CODE tags as in the forum rules. You have two warning already.
Using CODE tags means that the output will be fixed-width characters and multiple spaces will be respected

Last edited by rbatte1; 08-20-2014 at 07:58 AM.. Reason: Added CODE tags
# 14  
Old 08-20-2014
From your input of:-
Code:
ABCD172 2 B10001ú0E Fú08 DineshGú14 KumarNakkaú0E ú3C?INú14?EFGH340

.....I would expect this:-
Code:
ABCD172 2 B10001              F        DineshG                    KumarNakka              ????????????????????????????????????????????????????????????IN????????????????????EFGH340

.... which does not match your description of the expected output.

I'd still like to pursue how this is generated in the first place and see if there is a simpler alternative.



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