Printing special character in bash


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Printing special character in bash
# 1  
Old 01-02-2010
Printing special character in bash

I am using this character as a delimiter 'þ'
Currently, I set it straight:
DELIMITER='þ'

However, while copying the file, this character often gets mangled. Is there a bash way (perhaps using tr or printf) of generating this character.

It corresponds to

"chr(0xfe)" if using perl. (I've got it from the CRUSH tutorial
on CrushTutorial - crush-tools - A quick introduction to using CRUSH for data processing - Project Hosting on Google Code )

I essentially want to be able to say:

DELIMITER=$( printf "%x" 0xfe)

or $( echo 'x' | tr 'x' \xfe' )

or $( jot -c 1 0xfe )

All these give me junk characters.

Conversely, given some symbol can i gets its hex value in bash for future use.

If I do : jot 1 'þ'
I get -66.

---------- Post updated at 03:18 PM ---------- Previous update was at 02:50 PM ----------

I've found something, but is this the best way:

Code:
echo -n þ | hexdump

0000000 c3 be
0000002

Code:
echo -e "\xC3\xBE\x02"

þ
# 2  
Old 01-02-2010
This is the small letter thorn. With bash you can use:

Code:
$'\xFE'

For example:

Code:
bash-3.2.49(23)[~]$ echo $'\xFE'
þ

# 3  
Old 01-02-2010
you can also generate that byte, 0xFE, with printf(1) :

Code:
printf '\376'


Last edited by alister; 01-02-2010 at 09:50 AM..
# 4  
Old 01-04-2010
Quote:
Originally Posted by alister
you can also generate that byte, 0xFE, with printf(1) :

Code:
printf '\376'

Why do the last 2 print junk on my terminal.

Code:
 $ echo -e "\xC3\xBE\x02"
þ
 $ echo -e $'\xFE'
�
 $ printf '\376'
�

I'm on: GNU bash, version 4.0.35(1)-release (powerpc-apple-darwin9.8.0)

Code:
set | grep LC

LC_ALL=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
local LC_CTYPE=C;
# 5  
Old 01-04-2010
Sorry, I don't have access to a Mac so I cannot test.
With your code I get this on my terminal:

Code:
$ echo $'\xC3\xBE\02'
þ
$ echo $'\xC3\xBE'
þ
$ echo $'\xC3'
Ã
$ echo $'\xBE'
¾

And the codes seam to correspond to what I see (see the extended ascii table).

Did you check on another terminal or computer?
# 6  
Old 01-04-2010
Hello ,
You should config your terminal to ISO-8859-1 encoding .
In UTF-8 encoding you will need to use : echo -e "\xC3\xBE"


U+00FE LATIN SMALL LETTER THORN
General Character Properties
In Unicode since: 1.1
Unicode category: Letter, Lowercase
Various Useful Representations
UTF-8: 0xC3 0xBE
UTF-16: 0x00FE
C octal escaped UTF-8: \303\276
XML decimal entity: þ
Annotations and Cross References
Notes:
• Icelandic, Old English, phonetics
• Runic letter borrowed into Latin script
# 7  
Old 01-04-2010
Quote:
UTF-8: 0xC3 0xBE
Sure, thanks.
The OP uses the UTF-8 representation.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to understand special character for line reading in bash shell?

I am still learning shell scripting. Recently I see a function for read configuration. But some of special character make me confused. I checked online to find answer. It was not successful. I post the code here to consult with expert or guru to get better understanding on these special characters... (3 Replies)
Discussion started by: duke0001
3 Replies

2. UNIX for Beginners Questions & Answers

Escape bash-special character in a bash string

Hi, I am new in bash scripting. In my work, I provide support to several users and when I connect to their computers I use the same admin and password, so I am trying to create a script that will only ask me for the IP address and then connect to the computer without having me to type the user... (5 Replies)
Discussion started by: arcoa05
5 Replies

3. UNIX for Beginners Questions & Answers

Special character $$

Hi, on ksh What does the following do? grep -v "toolbox" $home_oracle/.profile >$home_oracle/.profile.$$ Thanks. Please use CODE tags as required by forum rules! (3 Replies)
Discussion started by: big123456
3 Replies

4. Shell Programming and Scripting

Vi special character

When editing a file, vi displays a special character as ^L. Can you tell me the escaped character to be used in awk? And can that escaped character be used in a regexp in both sed and awk? (7 Replies)
Discussion started by: dmesserly
7 Replies

5. Shell Programming and Scripting

Deleteing one character after an special character

I have below line in a unix file, I want to delete one character after "Â". 20091020.Non-Agency CMO Daily Trade Recap Â~V Hybrids The result should be : 20091020.Non-Agency CMO Daily Trade Recap  Hybrids i dont want to use "~V" anywhere in the sed command or any other command, just remove... (1 Reply)
Discussion started by: mohsin.quazi
1 Replies

6. Shell Programming and Scripting

Special character \

Hi, In the shell script, i need to remove the special charater "\" with "\\". For example, i need to replace "D:\FXT\ABC.TXT" with "D:\\FXT\\ABC.TXT". However, when trying to do something like , i get the below error :- -->echo "D:\FXT\ABC.TXT" | sed -e 's#\#\\#g' sed: 0602-404 Function... (7 Replies)
Discussion started by: amit_arora
7 Replies

7. UNIX for Dummies Questions & Answers

printing password having special characters

Hi I have a password stored in a file (which is a user input) The password is having the special character $ say the password is pw$ord and is stored in the file pw_note I am using the following statement to store the passowrd in a variable $schema_pwd = `cat $dir/pwd_note` ; Now if i print... (4 Replies)
Discussion started by: ssuresh1999
4 Replies

8. Shell Programming and Scripting

special character

Hi, I am trying to unload file from a database. Which contains few lines with the character below. Rest of the data was unloaded appropriately. a) What does this below character means? b) How can i remove it, I already have sed '/^$/d' c) Will this effect the file by any means... (4 Replies)
Discussion started by: tostay2003
4 Replies

9. UNIX for Dummies Questions & Answers

[OpenServer 5]Line Printing and special character (é @)

Hello, On Sco OpenServer 5, i want to print using the lpr command, no CUPS installed. I print on an HP LaserJet 4050 on LAN (IP 192.168.x.x) the printer is installed by HP Network Printer service. it works fine, but Specials characters, like é, @ or ° print bad characters. Is there... (5 Replies)
Discussion started by: tankd
5 Replies

10. Programming

special character ?

hey there im a bit stuck on executing commands that include the special character '?'. can someone recommend a way on how i would be able to execute it?? i thought the glob function could be useful (still mite be) but upon entering the command 'ls pars?' it listed all the files in the... (1 Reply)
Discussion started by: mile1982
1 Replies
Login or Register to Ask a Question