Sponsored Content
Full Discussion: Ascii value of character?
Top Forums UNIX for Dummies Questions & Answers Ascii value of character? Post 302234572 by Ygor on Wednesday 10th of September 2008 12:54:06 AM
Old 09-10-2008
Interesting. From info printf...
Quote:
* If the leading character of a numeric argument is `"' or `'' then
its value is the numeric value of the immediately following
character. Any remaining characters are silently ignored if the
`POSIXLY_CORRECT' environment variable is set; otherwise, a
warning is printed. For example, `printf "%d" "'a"' outputs `97'
on hosts that use the ASCII character set, since `a' has the
numeric value 97 in ASCII.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

ASCII character to accept logon password

Hey all, Just found your forum...Looks super rich with info! Can't wait to get through it all. I am currently writing a web app in .net that telnets into a unix server (require uid + passwd), runs a command, and returns that output to be displayed on the web page. I have gotten through the... (8 Replies)
Discussion started by: gord
8 Replies

2. UNIX for Dummies Questions & Answers

Non-ascii character detection (perl or grep)

Hi, Can I know how to grep for lines with non-ascii characters in a file? If not grep, at least can we do it with command-line perl or awk? I tried the functionality of perl, but still could not get the result. Any help?? PS: I was sure that someone should have asked this question... (9 Replies)
Discussion started by: srinivasan_85
9 Replies

3. Shell Programming and Scripting

read in a file character by character - replace any unknown ASCII characters with spa

Can someone help me to write a script / command to read in a file, character by character, replace any unknown ASCII characters with space. then write out the file to a new filename/ Thanks! (1 Reply)
Discussion started by: raghav525
1 Replies

4. UNIX for Dummies Questions & Answers

global search and replacement of a non-ascii character

Hi, I need to do a global search and replacement of a non-ascii character. Let me first give the background of my problem. Very frequently, I need to copy set of references from different sources. Typically, a reference would like this: Banumathy et al., 2002 G. Banumathy, V. Singh and U.... (1 Reply)
Discussion started by: effjay
1 Replies

5. UNIX for Advanced & Expert Users

ASCII Character Set

I thought I would point this out. This has a lot of the non printing characters. ASCII Character Set (7 Replies)
Discussion started by: cokedude
7 Replies

6. UNIX for Dummies Questions & Answers

How to grep for a non-standard ASCII character?

A very simple question but I have scoured the web and can't find an answer. How do I search for a character by ASCII code in a regular expression using grep? For example, we use the End of Medium symbol as a delimiter in certain files. (this is ascii 031 in oct, displays as ^Y) I want to grep... (6 Replies)
Discussion started by: DJR
6 Replies

7. Shell Programming and Scripting

FTP Issue with Non ascii character

I have one file .dat file on windows server containg the following text "Bürki" Now When I am using FTP (get) command from UNIX server the text is appering is as "Bürki" I want to preserve the text in the file on UNIX server as it is in source file. Could you please suggest some... (2 Replies)
Discussion started by: Bhushan D
2 Replies

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

9. Shell Programming and Scripting

Remove some special ascii character

Hello I have this special caracter after retreving rows from sql server: "....spasses: • Entrem al valort 6050108002811 • El donem..." I would like a sed command to remove it..or just know it's ascii code in order to replace it into my sql sentence.. Hope some one knows how to do that.... (7 Replies)
Discussion started by: ldiaz2106
7 Replies

10. UNIX for Dummies Questions & Answers

What is ASCII character?

Hi Guru, I have put one post yesterday and get answer. thanks for your help. my question today is: what is ascii character for following non printable characters: ( we need filter these characters out in another process) ^MM-^E^MM-^E. Old post link: ... (5 Replies)
Discussion started by: ken002
5 Replies
printf(1)						      General Commands Manual							 printf(1)

NAME
printf - Writes formatted output SYNOPSIS
printf format [argument...] STANDARDS
Interfaces documented on this reference page conform to industry standards as follows: printf: XCU5.0 Refer to the standards(5) reference page for more information about industry standards and associated tags. OPTIONS
None OPERANDS
A string describing the manner of writing the output. This string is explained in the DESCRIPTION section. The strings to be written under the control of the format. These strings are explained in the DESCRIPTION section. DESCRIPTION
The printf command converts, formats, and writes its arguments to the standard output. The values specified by the argument variable are formatted under control of the format variable. Syntax of the argument Variable The argument variable is a list of one or more strings to be written to the standard output under the control of the format variable. These are treated as strings if the corresponding conversion character is b, c, or s; otherwise, it is evaluated as a C constant, with the following extensions: A leading + (plus sign) or - (minus sign) is allowed. If the leading character is a ' (single quote) or " (double quote), the value is the numeric value in the underlying code set of the char- acter following the single quote or double quote. Syntax of the format Variable The format variable is a character string that contains three types of objects: Plain characters that are copied to the output stream. The following escape sequences are both copied to the output stream and cause the associated action to occur on display devices that are capa- ble of the action. Backslash Alert Backspace Formfeed Newline Carriage Return Tab Vertical Tab Where ddd is a one-, two-, or three-digit octal number. These escape sequences are displayed as a byte with the numeric value specified by the octal number. A delta character in the format string is treated as a delta character, rather than as a space character. The format variable is reused as often as necessary to satisfy the arguments. Any extra c or s conversion specifications are evaluated as if a null string argument were supplied; other extra conversion specifications are evaluated as if a zero argument were supplied. Each conversion specification in the format variable has the following syntax: A % (percent sign). Zero or more options, which modify the meaning of the conversion specification. The option characters and their meanings are as follows: The result of the conversion is left aligned within the field. The result of a signed conversion always begins with a + (plus) or - (minus). If the first character of a signed conversion is not a sign, a blank is prefixed to the result. If both the blank and + options appear, then the blank option is ignored. The value is converted to an alternative form. For c, d, i, u, and s conversions, the option has no effect. For o conversion, it increases the precision to force the first digit of the result to be a 0 (zero). For x and X conversions, a nonzero result has 0x, or 0X prefixed to it, respectively. For e, E, f, g, and G conversions, the result always contains a radix character, even if no digits follow the radix character. For g and G conversions, trailing zeros are not removed from the result as they usually are. For d, i, o, u, x, X, e, E, f, g, and G conversions, leading zeros (following any indication of sign or base) are used to pad to the field width, no space padding is performed. If the 0 (zero) and - options appear, the 0 (zero) option is ignored. For d, i, o, u, x, and X conversions, if a precision is specified, the 0 (zero) option is ignored. An optional decimal digit string that specifies the minimum field width. If the converted value has fewer characters than the field width, the field is padded on the left to the length specified by the field width. If the left- adjustment option flag (-) is specified, the field is padded on the right. An optional precision. The precision is a (dot) followed by an asterisk (*), or a decimal digit string. If no precision is given, it is treated as 0 (zero). The precision specifies: The minimum number of digits to appear for the d, o, i, u, x, or X conversions. The number of digits to appear after the radix character for the e and f con- versions. The maximum number of significant digits for the g conversion. The maximum number of bytes to be printed from a string in the s conversion. A character that indicates the type of conversion to be applied, as follows: Performs no conversion. Prints a % (percent sign). Accepts a value as a string that may contain backslash-escape sequences. Bytes from the converted string are printed until the end of the string or number of bytes indicated by the precision specification is reached. If the precision is omitted, all bytes until the first null character are printed. The following backslash-escape sequences are supported: The Oddd sequence, where ddd is a one-, two-, or three-digit octal number that is converted to a byte with the numeric value specified by the octal number. The escape sequences previously listed under the description of the format variable. These are converted to the individual characters they represented. The c sequence, which is not displayed and causes the printf command to ignore any remaining characters in the string parameter containing it, any remaining string parameters, and any additional characters in the format variable. Prints the first character of the argument. Accepts an integer value and converts it to a signed decimal notation in the style [-]dddd. The precision specifies the minimum number of dig- its to appear. If the value being converted can be represented in fewer digits, it is expanded with leading zeros. The default pre- cision is 1. The result of converting a 0 (zero) value with a precision of 0 (zero) is a null string. Specifying a field width with a 0 (zero) as a leading character causes the field to be padded with leading zeros. Accepts a float or double value and converts it to the exponential form [-] d.dde +|- dd. There is one digit before the radix character (shown here as the decimal point), and the number of digits after the radix character is equal to the precision specification. The LC_NUMERIC locale category determines the radix character to use in this format. If no precision is specified, then six digits are output. If the precision is 0 (zero), then no radix character appears. The E conversion character produces a number with E instead of e before the exponent. The exponent always contains at least two digits. However, if the value to be printed requires an exponent greater than two digits, additional exponent digits are printed as necessary. Accepts a float or double value and converts it to decimal notation in the format [-] ddd.ddd. The number of digits after the radix character (shown here as the decimal point) is equal to the precision specification. The LC_NUMERIC locale category determines the radix character to use in this format. If no precision is specified, then six digits are output. If the precision is 0 (zero), then no radix character appears. Accepts a float or double value and converts it in the style of the f or e conversion characters (or E in the case of the G conversion), with the precision specifying the number of sig- nificant digits. Trailing zeros are removed from the result. A radix character appears only if it is followed by a digit. The style used depends on the value converted. Style g results only if the exponent resulting from the conversion is less than -4, or if it is greater than or equal to the precision. Accepts an integer value and converts it to unsigned octal notation. The precision speci- fies the minimum number of digits to appear. If the value being converted can be represented in fewer digits, it is expanded with leading zeros. The default precision is 1. The result of converting a 0 (zero) value with a precision of 0 (zero) is a null string. Specifying a field width with a 0 (zero) as a leading character causes the field width value to be padded with leading zeros. An octal value for field width is not implied. Accepts a value as a string, and bytes from the string are printed until the end of the string is encountered or the number of bytes indicated by the precision is reached. If no precision is specified, all characters up to the first null character are printed. Accepts an integer value and converts it to unsigned decimal notation. The precision spec- ifies the minimum number of digits to appear. If the value being converted can be represented in fewer digits, it is expanded with leading zeros. The default precision is 1. The result of converting a 0 (zero) value with a precision of 0 (zero) is a null string. Specifying a field width with a 0 (zero) as a leading character causes the field width value to be padded with leading zeros. Accepts an integer value and converts it to unsigned hexadecimal notation. The letters abcdef are used for the x conversion and the letters ABCDEF are used for the X conversion. The precision specifies the minimum number of digits to appear. If the value being converted can be represented in fewer digits, it is expanded with leading zeros. The default precision is 1. The result of convert- ing a 0 (zero) value with a precision of 0 (zero) is a null string. Specifying a field width with a 0 (zero) as a leading character causes the field width value to be padded with leading zeros. If the result of a conversion is wider than the field width, the field is expanded to contain the converted result. No truncation occurs. However, a small precision may cause truncation on the right. EXAMPLES
The following printf command formats a series of numbers: printf "%5d%4d " 1 21 321 4321 54321 This command produces the following output: 1 21 3214321 54321 0 The format variable is used three times to print all of the given strings. The 0 (zero) is supplied by the printf command to satisfy the last %4d conversion specification. The following script includes printf commands to alert the user (sound a beep) and to dis- play prompts for entering a name and phone number. The script then appends the user entries to a file. printf "aPlease fill in the following: Name: " read name printf "Phone number: " read phone echo $name " " $phone >> phone_list echo >> phone_list ENVIRONMENT VARIABLES
The following environment variables affect the execution of printf: Provides a default value for the internationalization variables that are unset or null. If LANG is unset or null, the corresponding value from the default locale is used. If any of the internationalization variables contain an invalid setting, the utility behaves as if none of the variables had been defined. If set to a non-empty string value, overrides the values of all the other internationalization variables. Determines the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed to multibyte characters in arguments). Determines the locale for the format and contents of diagnostic messages written to standard error. Determines the location of message catalogues for the processing of LC_MESSAGES. Determines the locale for numbers written using the e, E, f, g, or G conversion characters. SEE ALSO
Commands: awk(1), bc(1), echo(1), read(1) Functions: printf(3) Standards: standards(5) printf(1)
All times are GMT -4. The time now is 06:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy