Replace alphabets in a string with their ASCII values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Replace alphabets in a string with their ASCII values
# 22  
Old 10-05-2016
In my lubuntu distribution with bash 4.3:
Code:
$ man -P "less -p printf" bash

Quote:
printf [-v var] format [arguments]
Write the formatted arguments to the standard output under the control of the format. The -v option causes the output to be assigned to the
variable var rather than being printed to the standard output.

The format is a character string which contains three types of objects: plain characters, which are simply copied to standard output, char‐
acter escape sequences, which are converted and copied to the standard output, and format specifications, each of which causes printing of
the next successive argument. In addition to the standard printf(1) format specifications, printf interprets the following extensions:
%b causes printf to expand backslash escape sequences in the corresponding argument (except that \c terminates output, backslashes in
\', \", and \? are not removed, and octal escapes beginning with \0 may contain up to four digits).
%q causes printf to output the corresponding argument in a format that can be reused as shell input.
%(datefmt)T
causes printf to output the date-time string resulting from using datefmt as a format string for strftime(3). The corresponding
argument is an integer representing the number of seconds since the epoch. Two special argument values may be used: -1 represents
the current time, and -2 represents the time the shell was invoked. If no argument is specified, conversion behaves as if -1 had
been given. This is an exception to the usual printf behavior.

Arguments to non-string format specifiers are treated as C constants, except that a leading plus or minus sign is allowed, and if the lead‐
ing character is a single or double quote, the value is the ASCII value of the following character.


The format is reused as necessary to consume all of the arguments. If the format requires more arguments than are supplied, the extra for‐
mat specifications behave as if a zero value or null string, as appropriate, had been supplied. The return value is zero on success, non-
zero on failure.
Regards.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

<< generate alphabets and append in the input values >>

Hi Team, Pls help to get the desired output. I have a input like below nodecount=10 host=na7-db1-1-chi nodecount can be 10 or 8 based on this we need a output (in single line) like below na7-db1-1-chi:A na7-db1-2-chi:B na7-db1-3-chi:C na7-db1-4-chi:D na7-db1-5-chi:E... (4 Replies)
Discussion started by: kamauv234
4 Replies

2. UNIX for Dummies Questions & Answers

Replace alphabets from certain positions

Hi all, I have column 2 full of values like HIVE4A-56 and HIVE4-56. I want to convert all values like HIVE4A-56 to HIVE4-56. So basically I want to delete all single alphabets before the '-' which is always preceded by a number. Values already in the desired format should remain unchanged... (4 Replies)
Discussion started by: ames1983
4 Replies

3. Shell Programming and Scripting

awk + gsub to search multiple input values & replace with located string + extra text

Hi all. I have the following command that is successfully searching for any one of the strings on all lines of a file and replacing it with the instructed value. cat inputFile | awk '{gsub(/aaa|bbb|ccc|ddd/,"1234")}1' > outputFile This does in fact replace any occurrence of aaa, bbb,... (2 Replies)
Discussion started by: dazhoop
2 Replies

4. Shell Programming and Scripting

Search for multiple string and replace with respective values

Hi, Can anyone help me to search for multiple strings within specified position and replace with respective string value. For example I need to search the string from the position 11 to 20 and if it contain ABC and then replace it by BCDEFGHIJ ... find AABZSDJIK and replace with QWE. and... (4 Replies)
Discussion started by: zooby
4 Replies

5. Shell Programming and Scripting

Incrementing ascii values

Hi All, I require some help with the below: I am trying to incriment the ascii value of a letter and then print it. So basically "a" becomes "b" and "z" becomes "A". Does anyone have any pointers? Cheers, Parks (10 Replies)
Discussion started by: bParks
10 Replies

6. Shell Programming and Scripting

Replace blank values for string using sed

Hi everyone, I was wondering how could from a file where each row is separated by tabulations, the row values where are in blank replace them by a string or value. My file has this form: 26/01/09 13:45:00 0 0 26/01/09 14:00:00 1495.601318 0 26/01/09 14:15:00 1495.601318 0 ... (4 Replies)
Discussion started by: tonet
4 Replies

7. Shell Programming and Scripting

How do i use sed to replace string with values from a dictionary file

I have file 1 with one million rows. one of the fields is "FIRSTNAME" (the string) I have a second file with about 20 first names. JUDE DAVID HOMER CANE ABEL MARTY CARL SONNY STEVE BERT OSCAR MICKY JAMES JOHN GLENN DOUG (3 Replies)
Discussion started by: yoyolandre
3 Replies

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

9. UNIX for Advanced & Expert Users

Converting Binary decimal coded values to Ascii Values

Hi All, Is there any command which can convert binary decimal coded values to ascii values... i have bcd values like below îîîîîîîîîîîî0î-- -v - Pls suggest a way to convert this. Thanks, Deepti.Gaur (3 Replies)
Discussion started by: gaur.deepti
3 Replies

10. Shell Programming and Scripting

Replace characters in a string using their ascii value

Hi All, In the HP Unix that i'm using when i initialise a string as Stalled="'30¬G'" Stalled=$Stalled" '30¬C'", it is taking the character ¬ as a comma. I need to grep for 30¬G 30¬C in a file and take its count. But since this character ¬ is not being understood, the count returns a zero. The... (2 Replies)
Discussion started by: roops
2 Replies
Login or Register to Ask a Question