Sponsored Content
Full Discussion: how to print off results
Top Forums Shell Programming and Scripting how to print off results Post 302592843 by Chubler_XL on Wednesday 25th of January 2012 05:16:21 AM
Old 01-25-2012
The "while read ip" statment populates the ip environment variable from the file 1 line at a time. and then executes all code to the done statement.

printf has the format of:
Code:
printf format_string arg1 arg2 arg3 ...

Here is a couple of examples - (check man printf for more):
Code:
printf "%10s%6.2f\n" test 12
      test 12.00
printf "Name: %s Age:%d\n" "John Jones" 25
Name: John Jones Age:25

So:
%10s formats first argument (test) as a 10 wide right justified string (Use %-10 for left justified)
%6.2f formats 2nd argument (12) as 6 (full stop and 2 digits count in width too) wide float with 2 decimal places
%s first argument (John Jones) as a variable width string
%d 2nd argument (25) as variable width integer.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

search file and print results with shell script

input file 1.<CRMSUB:MSIN=0100004735,BSNBC=TELEPHON-9814060328-TS11&TS21&TS22,NDC=9814,MSCAT=ORDINSUB,SUBRES=ALLPLMN-SPICE,BAOC=OIC,BAPRC=INFO,ACCSUB=BSS,NUMTYP=MULTI;... (3 Replies)
Discussion started by: dodasajan
3 Replies

2. Shell Programming and Scripting

Print just 1 results from the whole line

Hi All, need some help with writing a shell script. I tried to search this forum but couldn't find exactly what i want. If you all know any reference link i can read and refer to solve my issue, let me know. I got 1 file i.e: example.txt. It is content list of data, as below example. What... (2 Replies)
Discussion started by: anakiar
2 Replies

3. Shell Programming and Scripting

print first few lines, then apply regex on a specific column to print results.

abc.dat tty cpu tin tout us sy wt id 0 0 7 3 19 71 extended device statistics r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device 0.0 133.2 0.0 682.9 0.0 1.0 0.0 7.2 0 79 c1t0d0 0.2 180.4 0.1 5471.2 3.0 2.8 16.4 15.6 15 52 aaaaaa1-xx I want to skip first 5 line... (4 Replies)
Discussion started by: kchinnam
4 Replies

4. Shell Programming and Scripting

Script template for inputting filenames and print results

Hi, Hope you are all well. New to scripting, and all those characters are all a new language for me. Though hoping to get my little head round it all sooner or later. I was wondering whether anyone could help with a script template example. What I would like to happen is to run the script... (8 Replies)
Discussion started by: loky27
8 Replies

5. Shell Programming and Scripting

Print some results in a text file using script in linux

hello everyone, i really need your help to write a script which would just print following kind of result into a text file (result.txt) XYZ test Results ID: <unique-id> Date: <date> ------------------------------------------------- | Task | Result | Time |... (3 Replies)
Discussion started by: viriimind
3 Replies

6. Shell Programming and Scripting

How to print sed results

Dear all, How can I print results (and of course, send this result to the text file) of sed command. I mean, I want to know which lines of which files sed command has found. For e.g, the result text file should contains: file1.c:line 12 file2.h:line 14 file2.h:line 37 Please help me (10 Replies)
Discussion started by: Hannibal2010
10 Replies

7. Shell Programming and Scripting

Awk find in columns with "if then" statement and print results

I have a file1.txt file1.txt F-120009210","Felix","U-M-F-F-F-","white","yes","no","U-M-F-F-F-","Bristol","RI","true" F-120009213","Fluffy","U-F-","white","yes","no","M-F-","Warwick","RI","true" U-120009217","Lity","U-M-","grey","yes","yes","","Fall River","MA","true"... (4 Replies)
Discussion started by: charles33
4 Replies

8. UNIX for Dummies Questions & Answers

How to print results from two lines using awk?

I need to print a specific string from an html file that's always occurring between two other known strings. Example: from the text below, I would like to print the bolded part: <this is a lot of text before the string I want to print> fullpath: abc/def/ghi/example.xlf -cfver. <sample text... (15 Replies)
Discussion started by: danegon
15 Replies

9. Shell Programming and Scripting

Parsing OSX UNIX command results which print in multiple lines

from the CLI on a Mac, if you type networksetup -listallnetworkservices then you get results in a multi-line paragraph that look something like this: networksetup -listallnetworkservices An asterisk (*) denotes that a network service is disabled. Wi-Fi Display Ethernet Bluetooth DUN... (7 Replies)
Discussion started by: hungryd
7 Replies

10. Shell Programming and Scripting

Search for names in one list in another and print results

Hi All , New to the Bash / Shell programming world and looking for some help I have two files 1: Contains a list of names : eg STEVE BOB CRAIG 2: Contains information with those included names but also others that are not in the list (1 Reply)
Discussion started by: Lonerg550
1 Replies
printf(3UCB)					     SunOS/BSD Compatibility Library Functions					      printf(3UCB)

NAME
printf, fprintf, sprintf, vprintf, vfprintf, vsprintf - formatted output conversion SYNOPSIS
/usr/ucb/cc [flag ...] file ... #include <stdio.h> int printf( format, ...); const char *format; int fprintf( stream, format, va_list); FILE *stream; char *format; va_dcl; char *sprintf( s, format, va_list); char *s, *format; va_dcl; int vprintf(format, ap); char *format; va_list ap; int vfprintf( stream, format, ap); FILE *stream; char *format; va_list ap; char *vsprintf( s, format, ap); char *s, *format; va_list ap; DESCRIPTION
printf() places output on the standard output stream stdout. fprintf() places output on the named output stream. sprintf() places "output," followed by the NULL character (), in consecutive bytes starting at *s; it is the user's responsibility to ensure that enough storage is available. vprintf(), vfprintf(), and vsprintf() are the same as printf(), fprintf(), and sprintf() respectively, except that instead of being called with a variable number of arguments, they are called with an argument list as defined by <varargs.h>. Each of these functions converts, formats, and prints its args under control of the format. The format is a character string which contains two types of objects: plain characters, which are simply copied to the output stream, and conversion specifications, each of which causes conversion and printing of zero or more args. The results are undefined if there are insufficient args for the format. If the format is exhausted while args remain, the excess args are simply ignored. Each conversion specification is introduced by the character %. After the %, the following appear in sequence: o Zero or more flags, which modify the meaning of the conversion specification. o An optional decimal digit string specifying a minimum field width. If the converted value has fewer characters than the field width, it will be padded on the left (or right, if the left-adjustment flag `-', described below, has been given) to the field width. The padding is with blanks unless the field width digit string starts with a zero, in which case the padding is with zeros. o A precision that gives the minimum number of digits to appear for the d, i, o, u, x, or X conversions, the number of digits to appear after the decimal point for the e, E, and f conversions, the maximum number of significant digits for the g and G conversion, or the maximum number of characters to be printed from a string in s conversion. The precision takes the form of a period (.) followed by a decimal digit string; a NULL digit string is treated as zero. Padding specified by the precision overrides the padding specified by the field width. o An optional l (ell) specifying that a following d, i, o, u, x, or X conversion character applies to a long integer arg. An l before any other conversion character is ignored. o A character that indicates the type of conversion to be applied. A field width or precision or both may be indicated by an asterisk (*) instead of a digit string. In this case, an integer arg supplies the field width or precision. The arg that is actually converted is not fetched until the conversion letter is seen, so the args specifying field width or precision must appear before the arg (if any) to be converted. A negative field width argument is taken as a `-' flag fol- lowed by a positive field width. If the precision argument is negative, it will be changed to zero. The flag characters and their meanings are: - The result of the conversion will be left-justified within the field. + The result of a signed conversion will always begin with a sign (+ or -). blank If the first character of a signed conversion is not a sign, a blank will be prefixed to the result. This implies that if the blank and + flags both appear, the blank flag will be ignored. # This flag specifies that the value is to be converted to an "alternate form." For c, d, i, s, and u conversions, the flag has no effect. For o conversion, it increases the precision to force the first digit of the result to be a zero. For x or X conversion, a non-zero result will have 0x or 0X prefixed to it. For e, E, f, g, and G conversions, the result will always contain a decimal point, even if no digits follow the point (normally, a decimal point appears in the result of these conversions only if a digit follows it). For g and G conversions, trailing zeroes will not be removed from the result (which they normally are). The conversion characters and their meanings are: d,i,o,u,x,X The integer arg is converted to signed decimal (d or i), unsigned octal (o), unsigned decimal (u), or unsigned hexadecimal notation (x and X), respectively; the letters abcdef are used for x conversion and the letters ABCDEF for X conversion. The precision specifies the minimum number of digits to appear; if the value being converted can be represented in fewer dig- its, it will be expanded with leading zeroes. (For compatibility with older versions, padding with leading zeroes may alternatively be specified by prepending a zero to the field width. This does not imply an octal value for the field width.) The default precision is 1. The result of converting a zero value with a precision of zero is a NULL string. f The float or double arg is converted to decimal notation in the style [-]ddd.ddd where the number of digits after the deci- mal point is equal to the precision specification. If the precision is missing, 6 digits are given; if the precision is explicitly 0, no digits and no decimal point are printed. e,E The float or double arg is converted in the style [-]d.ddde+-ddd, where there is one digit before the decimal point and the number of digits after it is equal to the precision; when the precision is missing, 6 digits are produced; if the precision is zero, no decimal point appears. The E format code will produce a number with E instead of e introducing the exponent. The exponent always contains at least two digits. g,G The float or double arg is printed in style f or e (or in style E in the case of a G format code), with the precision spec- ifying the number of significant digits. The style used depends on the value converted: style e or E will be used only if the exponent resulting from the conversion is less than -4 or greater than the precision. Trailing zeroes are removed from the result; a decimal point appears only if it is followed by a digit. The e, E f, g, and G formats print IEEE indeterminate values (infinity or not-a-number) as "Infinity" or "NaN" respectively. c The character arg is printed. s The arg is taken to be a string (character pointer) and characters from the string are printed until a NULL character () is encountered or until the number of characters indicated by the precision specification is reached. If the precision is missing, it is taken to be infinite, so all characters up to the first NULL character are printed. A NULL value for arg will yield undefined results. % Print a %; no argument is converted. In no case does a non-existent or small 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. Padding takes place only if the specified field width exceeds the actual width. Characters generated by printf() and fprintf() are printed as if putc(3C) had been called. RETURN VALUES
Upon success, printf() and fprintf() return the number of characters transmitted, excluding the null character. vprintf() and vfprintf() return the number of characters transmitted. sprintf() and vsprintf() always return s. If an output error is encountered, printf(), fprint(), vprintf(), and vfprintf() return EOF. EXAMPLES
Example 1: Examples of the printf Command To Print a Date and Time To print a date and time in the form "Sunday, July 3, 10:02," where weekday and month are pointers to NULL-terminated strings: printf("%s, %s %i, %d:%.2d", weekday, month, day, hour, min); Example 2: Examples of the printf Command To Print to Five Decimal Places To print to five decimal places: printf("pi = %.5f", 4 * atan(1. 0)); SEE ALSO
econvert(3C), putc(3C), scanf(3C), vprintf(3C) NOTES
Use of these interfaces should be restricted to only applications written on BSD platforms. Use of these interfaces with any of the system libraries or in multi-thread applications is unsupported. Very wide fields (>128 characters) fail. SunOS 5.10 18 Feb 1993 printf(3UCB)
All times are GMT -4. The time now is 04:29 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy