Sponsored Content
Top Forums Shell Programming and Scripting Extended ASCII Characters keep on getting reintroduced to text files Post 302976993 by wisecracker on Sunday 10th of July 2016 01:44:41 PM
Old 07-10-2016
Using the very limited info, done longhand.
Each line in the file contains a single ' and " .
Not sure if this a just a very small part of the string but here goes.
Code:
#¡/bin/bash
# nonascii.sh
# Macbbok Pro, circa August 2012, OSX 10.7.5, deafult  bash terminal.
> /tmp/nonascii.dat
> /tmp/newascii.txt
# Create 3 lines of data as per the very limited info.
printf "%s\n" "▒▒Gateway1,Gateway2 ▒▒4▒d▒U4▒"\'"E\"▒morel" >> /tmp/nonascii.dat
printf "%s\n" "▒▒Gateway1,Gateway2 ▒▒4▒d▒U4▒"\'"E\"▒morel" >> /tmp/nonascii.dat
printf "%s\n" "▒▒Gateway1,Gateway2 ▒▒4▒d▒U4▒"\'"E\"▒morel" >> /tmp/nonascii.dat
cat /tmp/nonascii.dat
# Now remove non-ascii characters, Backspace character, (127 decimal), also removed here.
length=$( wc -c < /tmp/nonascii.dat )
deci_string=( $( od -tu1 -An < /tmp/nonascii.dat ) )
for n in $( seq 0 1 $((length-1)) )
do
	if [ "${deci_string[$n]}" -le "126" ]
	then
		printf '\x'$( printf "%x" "${deci_string[$n]}" )
	fi
done > /tmp/newascii.txt
# Prove extended characters have gone.
cat /tmp/newascii.txt

Results:-
Code:
Last login: Sun Jul 10 18:34:52 on ttys000
AMIGA:barrywalker~> cd Desktop/Code/Shell
AMIGA:barrywalker~/Desktop/Code/Shell> ./nonascii.sh
▒▒Gateway1,Gateway2 ▒▒4▒d▒U4▒'E"▒morel
▒▒Gateway1,Gateway2 ▒▒4▒d▒U4▒'E"▒morel
▒▒Gateway1,Gateway2 ▒▒4▒d▒U4▒'E"▒morel
Gateway1,Gateway2 4dU4'E"morel
Gateway1,Gateway2 4dU4'E"morel
Gateway1,Gateway2 4dU4'E"morel
AMIGA:barrywalker~/Desktop/Code/Shell> _

 

10 More Discussions You Might Find Interesting

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

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

3. Shell Programming and Scripting

convert ascii values into ascii characters

Hi gurus, I have a file in unix with ascii values. I need to convert all the ascii values in the file to ascii characters. File contains nearly 20000 records with ascii values. (10 Replies)
Discussion started by: sandeeppvk
10 Replies

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

5. Shell Programming and Scripting

Extended replacing of nonspecific strings in text files [beware complicated !]

Well, to make another post at this helpful forum :b::D: I recently tried something like this, I want to replace all those numberings/letters that are located between <string>file://localhost/var/mobile/Applications/ and /Documents/</string> numberings =---- replace with: first... (6 Replies)
Discussion started by: pasc
6 Replies

6. Shell Programming and Scripting

Identify extended ascii characters in a file

Hi, Is there a way to identify the lines in a file having extended ascii characters and display the same? For instance I have a file abc.txt having below data aaa|bbb|111|This is first line aaa|bbb|222|This is secõnd line aaa|bbb|333|This is third line aaa|bbb|444|This is foùrth line... (3 Replies)
Discussion started by: decci_7
3 Replies

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

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

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

10. UNIX for Beginners Questions & Answers

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 (38 Replies)
Discussion started by: rosebud123
38 Replies
ASCII(1)						      General Commands Manual							  ASCII(1)

NAME
ascii, unicode - interpret ASCII, Unicode characters SYNOPSIS
ascii [ -8 ] [ -oxdbn ] [ -nct ] [ text ] unicode [ -nt ] hexmin-hexmax unicode [ -t ] hex [ ... ] unicode [ -n ] characters look hex /lib/unicode DESCRIPTION
Ascii prints the ASCII values corresponding to characters and vice versa; under the -8 option, the ISO Latin-1 extensions (codes 0200-0377) are included. The values are interpreted in a settable numeric base; -o specifies octal, -d decimal, -x hexadecimal (the default), and -bn base n. With no arguments, ascii prints a table of the character set in the specified base. Characters of text are converted to their ASCII val- ues, one per line. If, however, the first text argument is a valid number in the specified base, conversion goes the opposite way. Control characters are printed as two- or three-character mnemonics. Other options are: -n Force numeric output. -c Force character output. -t Convert from numbers to running text; do not interpret control characters or insert newlines. Unicode is similar; it converts between UTF and character values from the Unicode Standard (see utf(7)). If given a range of hexadecimal numbers, unicode prints a table of the specified Unicode characters -- their values and UTF representations. Otherwise it translates from UTF to numeric value or vice versa, depending on the appearance of the supplied text; the -n option forces numeric output to avoid ambigu- ity with numeric characters. If converting to UTF , the characters are printed one per line unless the -t flag is set, in which case the output is a single string containing only the specified characters. Unlike ascii, unicode treats no characters specially. The output of ascii and unicode may be unhelpful if the characters printed are not available in the current font. The file /lib/unicode contains a table of characters and descriptions, sorted in hexadecimal order, suitable for look(1) on the lower case hex values of characters. EXAMPLES
ascii -d Print the ASCII table base 10. unicode p Print the hex value of `p'. unicode 2200-22f1 Print a table of miscellaneous mathematical symbols. look 039 /lib/unicode See the start of the Greek alphabet's encoding in the Unicode Standard. FILES
/lib/unicode table of characters and descriptions. SOURCE
/src/cmd/ascii.c /src/cmd/unicode.c SEE ALSO
look(1), tcs(1), utf(7), font(7) ASCII(1)
All times are GMT -4. The time now is 05:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy