Sponsored Content
Top Forums Shell Programming and Scripting perl: simple question on string append Post 302117481 by jim mcnamara on Monday 14th of May 2007 05:09:26 PM
Old 05-14-2007
Code:
$result = sprintf("%.2f", $number);

 

10 More Discussions You Might Find Interesting

1. Programming

simple question on string concat

This is a simple question... char *str = NULL; int num = 0; scanf ("%d", &num); str = ??? I want str to point to the string num.txt For e.g: If user enters num = 5, str should point to "5.txt" How do I do that ? Thanks (2 Replies)
Discussion started by: the_learner
2 Replies

2. Shell Programming and Scripting

PERL: simple comparing arrays question

Hi there, i have been trying different methods and i wonder if somebody could explain to me how i would perform a comparison on two arrays for example my @array1 = ("gary" ,"peter", "paul"); my @array2 = ("gary" ,"peter", "joe"); I have two arrays above, and i want to something like this... (5 Replies)
Discussion started by: hcclnoodles
5 Replies

3. Shell Programming and Scripting

Simple perl question

I am totally new to perl. I am modifying someone else's script. I have the following output: # ./some-perlscript A B C D E B - E, is generated through the print command that I put in the script. I want to remove A, it seems it is generated automatically by a custom OS it is querying when... (3 Replies)
Discussion started by: streetfighter2
3 Replies

4. Shell Programming and Scripting

how to append a string to next line in perl

hi all , i have a requirement like this.. this just a sample script... $ cat test.sh #!/bin/bash perl -e ' open(IN,"addrss"); open(out,">>addrss"); @newval; while (<IN>) { @col_val=split(/:/); if ($.==1) { for($i=0;$i<=$#col_val;$i++) { ... (2 Replies)
Discussion started by: tprayush
2 Replies

5. Shell Programming and Scripting

Simple Question about Reading file by Perl

Hi , I just write a simple function to read the file line by line. But when I run it it says out of memory. I am not sure about the root cause, Can someone help me out of this? :D #! /usr/bin/perl use strict; sub checkAPs{ my $NDPDir = "/home/eweiqqu/NCB/NDP_files/"; ... (1 Reply)
Discussion started by: Damon_Qu
1 Replies

6. UNIX for Dummies Questions & Answers

Append a string on the next line after a pattern string is found

Right now, my code is: s/Secondary Ins./Secondary Ins.\ 1/g It's adding a 1 as soon as it finds Secondary Ins. Primary Ins.: MEDICARE B DMERC Secondary Ins. 1: CONTINENTAL LIFE INS What I really want to achieve is having a 1 added on the next line that contain "Secondary Ins." It... (4 Replies)
Discussion started by: newbeee
4 Replies

7. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

8. Red Hat

Syslog.conf: looking for a simple answer on a simple question

Cheers! In /etc/syslog.conf, if an error type is not specified, is it logged anywhere (most preferable is it logged to /var/log/messages) or not? To be more precise I am interested in error and critical level messages. At default these errors are not specified in syslog.conf, and I need to... (6 Replies)
Discussion started by: dr1zzt3r
6 Replies

9. Shell Programming and Scripting

Simple Perl question

Hello, I'm completely new to Perl and I'm just looking for a quick answer to some code I'm trying to come up with. I'm trying to access a website, part of the URL I want the user to be able to define via standard input. As you can see below I'm still trying to get the syntax. ... (2 Replies)
Discussion started by: wxornot
2 Replies

10. Shell Programming and Scripting

Perl String Replacement Syntax Question . . .

Greetings! I've been tooling about with Perl to make a few string replacements in some files; and seem to have run into a bit of a squeeze :) Beginning with a simple text file, test.txt, we have the following content to be worked:Now, not wanting to have anyone feel left out, I decided that... (6 Replies)
Discussion started by: LinQ
6 Replies
sprintf(9F)						   Kernel Functions for Drivers 					       sprintf(9F)

NAME
sprintf, snprintf - format characters in memory SYNOPSIS
#include <sys/ddi.h> char *sprintf(char *buf, const char *fmt, ...); size_t snprintf(char *buf, size_t n, const char *fmt, ...); INTERFACE LEVEL
Solaris DDI specific (Solaris DDI). PARAMETERS
buf Pointer to a character string. fmt Pointer to a character string. DESCRIPTION
sprintf() builds a string in buf under the control of the format fmt. The format is a character string with either plain characters, which are simply copied into buf, or conversion specifications, each of which converts zero or more arguments, again copied into buf. The results are unpredictable if there are insufficient arguments for the format; excess arguments are simply ignored. It is the user's responsibility to ensure that enough storage is available for buf. The snprintf() function is identical to sprintf() with the addition of the argument n, which specifies the size of the buffer referred to by buf. The buffer is always terminated with the null byte. Conversion Specifications Each conversion specification is introduced by the % character, after which the following appear in sequence: An optional value specifying a minimum field width for numeric conversion. The converted value will be right-justified and, if it has fewer characters than the minimum, is padded with leading spaces unless the field width is an octal value, then it is padded with leading zeroes. An optional l (ll) specifying that a following d, D, o, O, x, X, or u conversion character applies to a long (long long) integer argument. An l (ll) before any other conversion character is ignored. A character indicating the type of conversion to be applied: d,D,o,O,x,X,u The integer argument is converted to signed decimal (d, D), unsigned octal (o, O), unsigned hexadecimal (x, X) or unsigned decimal (u), respectively, and copied. The letters abcdef are used for x conversion. The letters ABCDEF are used for X conversion. c The character value of argument is copied. b This conversion uses two additional arguments. The first is an integer, and is converted according to the base specified in the second argument. The second argument is a character string in the form <base>[<arg>...]. The base supplies the conversion base for the first argument as a binary value; 10 gives octal, 20 gives hexadecimal. Each subsequent <arg> is a sequence of characters, the first of which is the bit number to be tested, and subsequent characters, up to the next bit number or terminating null, supply the name of the bit. A bit number is a binary-valued character in the range 1-32. For each bit set in the first argument, and named in the second argument, the bit names are copied, separated by commas, and bracketed by < and >. Thus, the following function call would generate reg=3<BitTwo,BitOne> in buf. sprintf(buf, "reg=%b ", 3, "102BitTwo1BitOne") p The argument is taken to be a pointer; the value of the pointer is displayed in unsigned hexadecimal. The display format is equivalent to %lx. To avoid lint warnings, cast pointers to type void * when using the %p format specifier. s The argument is taken to be a string (character pointer), and characters from the string are copied until a null character is encoun- tered. If the character pointer is NULL, the string <null string> is used in its place. % Copy a %; no argument is converted. RETURN VALUES
sprintf() returns its first argument, buf. snprintf() returns the number of characters formatted, that is, the number of characters that would have been written to the buffer if it were large enough. If the value of n is less than or equal to 0 on a call to snprintf(), the function simply returns the number of charac- ters formatted. CONTEXT
sprintf() and snprintf() can be called from user or interrupt context. SEE ALSO
Writing Device Drivers SunOS 5.10 11 Feb 2003 sprintf(9F)
All times are GMT -4. The time now is 09:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy