Sponsored Content
Top Forums Shell Programming and Scripting awk treating variables differently in UNIX-Linux Post 302980769 by wanderingmind16 on Friday 2nd of September 2016 03:48:29 AM
Old 09-02-2016
Yes, thank you Don Cragun. I posted it about printf before I read your reply.

Is there any way I can make it compatible to the UNIX code with %s? If not, how can I tell printf to format a variable with leading zeros no matter if it is an integer or string.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

assign a command line argument and a unix command to awk variables

Hi , I have a piece of code ...wherein I need to assign the following ... 1) A command line argument to a variable e.g origCount=ARGV 2) A unix command to a variable e.g result=`wc -l testFile.txt` in my awk shell script When I do this : print "origCount" origCount --> I get the... (0 Replies)
Discussion started by: sweta_doshi
0 Replies

2. Programming

How to convert byteArray variables to HexaString variables for Linux?

Hello everybody, I am having problem in converting byte array variables to Hexa String variables for Linux. I have done, converting byte array variables to Hexa String variables for Windows but same function doesn't work for linux. Is there any difference in OS ? The code for Windows is given... (2 Replies)
Discussion started by: ritesh_163
2 Replies

3. Shell Programming and Scripting

simple CSH Script behaves differently on Solaris and RedHat Linux

I have a simple csh-script on a Solaris Workstaion which invokes the bc calculator: #!/bin/csh set shz=2 set zshift=5 set shzp=`bc -l <<END \ scale = 3 \ -1. * $shz + $zshift \ END` echo $shzp The result ($shzp) in this case is 3 (-1*2+5). It works fine on Solaris 8. ... (2 Replies)
Discussion started by: two reelers
2 Replies

4. Windows & DOS: Issues & Discussions

Awk script in DOS and Linux behaves differently :(

Hi, I have an awk script which performs simple operations of variable assignments and finally printing the variables in custom form. BEGIN {FS=OFS="\n"} { v1=substr($0,1,15) v2=substr($0,16,200) v3=substr($0,216,20) print v1 "|" v2 "|" v3 } The input file being processed... (2 Replies)
Discussion started by: vidyak
2 Replies

5. UNIX for Advanced & Expert Users

Unix script rm behaiving differently in difference machine

Hi All The below is the script, if i supply the script with the argument -f then it will delete the tmp file . We are having 3 unix system out of that two system are processing this file only one system is not processing and the error showin is below the script .. can you please help me ... (2 Replies)
Discussion started by: arunkumar_mca
2 Replies

6. Shell Programming and Scripting

awk - treating remaining columns as one

Hi all, For no particular reason, I would like to use awk on a file that contains multiple columns, but let's say only columns 1 and 2 have some text values, and the remainder of the line contains text that I would like to treat as one column, considering I have spaces as delimiter for the... (33 Replies)
Discussion started by: ppucci
33 Replies

7. Shell Programming and Scripting

awk script modification - treat certain files differently

awk 'BEGIN{OFS=","} FNR == 1 {if (NR > 1) {print fn,fnr,nl} fn=FILENAME; fnr = 1; nl = 0} {fnr = FNR} /UNUSUAL/ && /\.gz/ ~ /FILENAME/ {nl++} <'{system ("gunzip -cd FILENAME")}' END ... (2 Replies)
Discussion started by: SkySmart
2 Replies

8. Shell Programming and Scripting

Passing awk variables to bash variables

Trying to do so echo "111:222:333" |awk -F: '{system("export TESTO=" $2)}'But it doesn't work (2 Replies)
Discussion started by: urello
2 Replies

9. Shell Programming and Scripting

Why awk perform differently when using variable?

Hi Gurus, I hit a hard block in my script. when using awk command with variable, I got different result. Please see below: my test file as below: $ cat demofile.txt filename-yyyy-abcd filename-xxx-week-pass filename-xxx-week-run for testing purpose, I put 3 awk command in one script.... (7 Replies)
Discussion started by: ken6503
7 Replies

10. Shell Programming and Scripting

AIX to RHEL migration - awk treating 0e[0-9]+ as 0 instead of string issue

Greetings Experts, We are migrating from AIX to RHEL Linux. I have created a script to verify and report the NULLs and SPACEs in the key columns and duplicates on key combination of "|" delimited set of big files. Following is the code that was successfully running in AIX. awk -F "|" 'BEGIN {... (5 Replies)
Discussion started by: chill3chee
5 Replies
printf(1)						      General Commands Manual							 printf(1)

NAME
printf - format and print arguments SYNOPSIS
format [arg ...] DESCRIPTION
writes formatted arguments to the standard output. The arg arguments are formatted under control of the format operand. format is a character string patterned after the formatting conventions of (see printf(3S)), and contains the following types of objects: characters Characters that are not escape sequences or conversion specifications (as described below) are copied to stan- dard output. escape sequences These are interpreted as non-graphic characters: alert backspace form-feed new-line carriage return tab vertical tab single quote character backslash the 8-bit character whose ASCII code is the 1-, 2-, 3-, or 4-digit octal number n, whose first character must be a zero. conversion specification Specifies the output format of each argument (see below). Arguments following format are interpreted as strings if the corresponding format is either or otherwise they are treated as con- stants. Conversion Specifications Each conversion specification is introduced by the percent character After the character, the following can appear in the sequence indi- cated: flags Zero or more flags, in any order, which modify the meaning of the conversion specification. The flag characters and their meanings are: The result of the conversion is left-justified within the field. The result of a signed conversion always begins with a sign, or <space> If the first character of a signed conversion is not a sign, a space character is prefixed to the result. This means that if the space flag and flag both appear, the space flag is ignored. The value is to be converted to an "alternate form". For and conversions, this flag has no effect. For conversion, it increases the precision to force the first digit of the result to be a zero. For or conversion, a non-zero result has or prefixed to it. For and conversions, the result always contains a radix character, even if no digits follow the radix character. For and conversions, trailing zeros are not removed from the result, contrary to usual behavior. field width An optional string of decimal digits to specify a minimum field width. For an output field, if the converted value has fewer bytes than the field width, it is padded on the left (or right, if the left-adjustment flag, has been given) to the field width. precision The precision specifies the minimum number of digits to appear for the or conversions (the field is padded with leading zeros), the number of digits to appear after the radix character for the and conversions, the maximum number of signifi- cant digits for the conversion, or the maximum number of bytes to be printed from a string in s conversion. The preci- sion takes the form of a period followed by a decimal digit string. A null digit string is treated as a zero. conversion characters A conversion character indicates the type of conversion to be applied: The integer argument is printed a signed decimal or unsigned octal unsigned decimal or unsigned hexadecimal notation and The conversion uses the numbers and letters and the conversion uses the numbers and letters The precision component of the argument specifies the minimum number of digits to appear. If the value being converted can be represented in fewer digits than the specified minimum, it is expanded with leading zeroes. The default precision is 1. The result of converting a zero value with a precision of 0 is no characters. The floating-point number argument is printed in decimal notation in the style , where the number of digits after the radix character, is equal to the precision specification. If the precision is omitted from the argument, six digits are out- put; if the precision is explicitly 0, no radix appears. The floating-point-number argument is printed in the style , where there is one digit before the radix character, and the number of digits after it is equal to the precision. When the precision is missing, six digits are produced; if the precision is 0, no radix charac- ter appears. The conversion character produces a number with introducing the exponent instead of The expo- nent 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. The floating-point-number argument is printed in style or (or int style in the case of a conversion character), with the precision specifying the number of sig- nificant digits. The style used depends on the value converted; style is used only if the exponent result- ing from the conversion is less than or greater than or equal to the precision. Trailing zeros are remove from the result. A radix character appears only if it is followed by a digit. The first byte of the argument is printed. The argument is taken to be a string, and characters from the string are printed until the end of the string or the number of bytes indicated by the precision specification of the argument is reached. If the precision is omitted from the argument, it is interpreted as infinite and all characters up to the end of the string are printed. Print a character; no argument is converted. Similar to the conversion specifier, except that the string can contain backslash-escape sequences which are then con- verted to the characters they represent. will cause to ignore any remaining characters in the string oper- and containing it, any remaining string operands and any additional characters in the format operand. In no case does a nonexistent or insufficient field width cause truncation of a field; if the result of a conversion is wider than the field width, the field is simply expanded to contain the conversion result. EXTERNAL INFLUENCES
Environment Variables determines the interpretation of arg as single and/or multi-byte characters. determines the language in which messages are displayed. If or is not specified in the environment or is set to the empty string, the value of is used as a default for each unspecified or empty variable. If is not specified or is set to the empty string, a default of "C" (see lang(5)) is used instead of If any internationalization variable contains an invalid setting, printf behaves as if all internationalization variables are set to "C". See environ(5). International Code Set Support Single and multi-byte character code sets are supported. RETURN VALUE
exits with one of the following values: Successful completion. Errors occurred; the exit value is increased by one for each error that occurred up to a maximum of 255. DIAGNOSTICS
If an argument cannot be converted into a form suitable for the corresponding conversion specification, or for any other reason cannot be correctly printed, a diagnostic message is printed to standard error, the argument is output as a string form as it was given on the com- mand line, and the exit value is incremented. EXAMPLES
The following command prints the number 123 in octal, hexadecimal and floating point formats in their alternate form printf "%#o, %#x, %#X, %#f, %#g, %#e " 123 123 123 123 123 123 resulting in the following output Print the outputs with their corresponding field widths and precision: printf "%.6d, %10.6d, %.6f, %.6e, %.6s " 123 123 1.23 123.4 MoreThanSix resulting in the following output SEE ALSO
echo(1), printf(3S). STANDARDS CONFORMANCE
printf(1)
All times are GMT -4. The time now is 10:12 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy