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
LTRIM(3)								 1								  LTRIM(3)

ltrim - Strip whitespace (or other characters) from the beginning of a string

SYNOPSIS
string ltrim (string $str, [string $character_mask]) DESCRIPTION
Strip whitespace (or other characters) from the beginning of a string. PARAMETERS
o $str - The input string. o $character_mask - You can also specify the characters you want to strip, by means of the $character_mask parameter. Simply list all characters that you want to be stripped. With .. you can specify a range of characters. RETURN VALUES
This function returns a string with whitespace stripped from the beginning of $str. Without the second parameter, ltrim(3) will strip these characters: o " " (ASCII 32 ( 0x20)), an ordinary space. o " " (ASCII 9 ( 0x09)), a tab. o " " (ASCII 10 ( 0x0A)), a new line (line feed). o " " (ASCII 13 ( 0x0D)), a carriage return. o "" (ASCII 0 ( 0x00)), the NUL-byte. o "x0B" (ASCII 11 ( 0x0B)), a vertical tab. EXAMPLES
Example #1 Usage example of ltrim(3) <?php $text = " These are a few words :) ... "; $binary = "x09Example stringx0A"; $hello = "Hello World"; var_dump($text, $binary, $hello); print " "; $trimmed = ltrim($text); var_dump($trimmed); $trimmed = ltrim($text, " ."); var_dump($trimmed); $trimmed = ltrim($hello, "Hdle"); var_dump($trimmed); // trim the ASCII control characters at the beginning of $binary // (from 0 to 31 inclusive) $clean = ltrim($binary, "x00..x1F"); var_dump($clean); ?> The above example will output: string(32) " These are a few words :) ... " string(16) " Example string " string(11) "Hello World" string(30) "These are a few words :) ... " string(30) "These are a few words :) ... " string(7) "o World" string(15) "Example string " SEE ALSO
trim(3), rtrim(3). PHP Documentation Group LTRIM(3)
All times are GMT -4. The time now is 04:26 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy