Print byte position of extended ascii character

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Print byte position of extended ascii character
# 1  
Old 07-14-2018
Wrench Print byte position of extended ascii character

Hello,

I am on AIX.

When I encounter extended ascii characters and special characters on a file I need to print..

Byte position, actual character and line number.

Is there a simple command that can give me the above result ?

Thanks in advance
# 2  
Old 07-14-2018
Welcome to the forum.

Please become accustomed to provide decent context info of your problem.

It is always helpful to carefully and detailedly phrase a request, and to support it with system info like OS and shell, related environment (variables, options), preferred tools, adequate (representative) sample input and desired output data and the logics connecting the two including your own attempts at a solution, and, if existent, system (error) messages verbatim, to avoid ambiguities and keep people from guessing.


Please specify what you mean by "extended ascii characters" and "special characters". You're not talking of code sets like UTF-8 but more of code pages, I presume?
# 3  
Old 07-14-2018
Thanks RudiC.

I am talking about the extended ascii set , please see the extended ascii table from the below link

Sorry if i am using CODE tag at incorrect location , I am not allowed to post the link so I used the code tag

Code:
ascii-table.com/ascii-extended-pc-list.php

# 4  
Old 07-14-2018
OK.
This is about a third of the required answers.
# 5  
Old 07-14-2018
I am making an assumption that you are looking for ISO-8859-1, 8 bit extensions where the extended characters are NOT like Code Page 437.

You could try something like 'hexdump' to get a 'subscript' position from 0 to the length of line, with 8 bit values 128 and above...
VALUE=$( hexdump -n1 -s$SUBSCRIPT -v -e '1/1 "%u"' /full/path/to/file )
..Where VALUE is a decimal number from 0 to 255 and SUBSCRIPT is the position in each line read. this could even give the positions of all characters greater than 127 with the correct filtering.
This might help for your requirements:
Another Building Block, Binary File Manipulation...
# 6  
Old 07-14-2018
Howsoever, try
Code:
while read T
  do    ((CNT++))
        for ((i=0; i<${#T}; i++))
          do    LC_ALL=C TMP=$(printf "%d\n" "'"${T:i:1})
                [ $TMP -gt 127 ] && printf "%d %c %d\n" $i ${T:i:1} $CNT
          done
  done <file

This User Gave Thanks to RudiC For This Post:
# 7  
Old 07-14-2018
Here is the source file and the desired output file

Source File

Code:
MDQ ŸD201803132018031400
MDQ "ã201707112018071100
MDQ =ÿ201605202018052000
MDQ "Ä201605202018052000
QDX ûÁ201705012018050200
MDQ ì©201708102018081000
QDU ìc-201708092018080900

Desired Output

Code:
BytePosition	Special_Chracter     Linen_Number             Special_Character_Count    Total_Count_of_Special_Chracaters_In_file
5	          	                     1                           1                      1
6                 Ÿ                          1                           1                      1
5	                                    2                           1                      1
6                 ã                          2                           1                      1
5	                                    3                           1                      2
6                 ©                          6                           1                      1

Total_Count_of_Special_Chracaters_In_file column value is the total occurrence of the character in the input file.

In the above example  appeared twice once in record number 2 and once in record number 3 , so for this special character  Total_Count_of_Special_Chracaters_In_file is '2'

Thanks in advance!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Removal Extended ASCII using awk

Hi All, I am trying to remove (SELECTIVE - passed as argument) Extended ASCII using Awk based on adhoc basis. Can you please let me know how to do it. I have to implement this using awk only. Thanks & Regads (14 Replies)
Discussion started by: tostay2003
14 Replies

2. Programming

How to read extended ASCII characters from stdin?

Hi, I want to read extended ASCII characters from keyboard using c language on unix/linux. How to read extended characters from keyboard or by copy-paste in terminal irrespective of locale set in the system. I want to read the input characters from keyboard, store it in an array or some local... (3 Replies)
Discussion started by: sanzee007
3 Replies

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

4. Shell Programming and Scripting

Print the next ASCII character

Hi, In my file, for few field I have to print the next ASCII character for every character. In the below file, I have to do for the 2,3 and 5th fields. Input File ======== 1|abc|def|5|ghi 2|jkl|mno|6|pqr Expected Ouput file ======= 1|bcd|efg|5|hij 2|klm|nop|6|qrs (2 Replies)
Discussion started by: machomaddy
2 Replies

5. AIX

Printing extended ASCII

Hi All, I'm trying to send extended ascii characters to my HP2055 as part of PCL printer control codes. What I want to do is select a bar code font, print the bar code and reset the printer to the default font. Selecting the bar code font works good. Printing the bar code goes almost ok too. ... (5 Replies)
Discussion started by: petervg
5 Replies

6. Shell Programming and Scripting

Print lines with specific character at nth position in a file

I need to print lines with character S at nth position in a file...can someone pl help me with appropriate awk command for this (1 Reply)
Discussion started by: manaswinig
1 Replies

7. Shell Programming and Scripting

Print lines with specific character at nth position in a file

I need to print lines with character S at nth position in a file...can someone pl help me with appropriate awk command for this (2 Replies)
Discussion started by: manaswinig
2 Replies

8. UNIX for Advanced & Expert Users

Processing extended ascii character file names in UNIX (BASH scipts)

Hi, I have a accentuated letter (ö) in a script for an Installer. It's a file name. This is not working and I'm told to try using the octal value for the extended ascii character. Does anyone no how to do this? If I had the word "filförval", can I just put in the value between the letters, like... (9 Replies)
Discussion started by: peli
9 Replies

9. Shell Programming and Scripting

extended ascii problem

hi i would like to check text files if they contain extended ascii characters within or not. i really dont have any idea how to start your kind help would be very much appreciated thanks. (7 Replies)
Discussion started by: smooth
7 Replies

10. Programming

Extended ascii

Hi all, I would like to change the extended ascii code ( 128 - 255). I tried to change LC_ALL and LANG in current session ( values from locale -a) and for no good. Thanks. (0 Replies)
Discussion started by: avis
0 Replies
Login or Register to Ask a Question