Sponsored Content
Full Discussion: Trimming the spaces
Top Forums UNIX for Advanced & Expert Users Trimming the spaces Post 302212267 by arunk2000 on Monday 7th of July 2008 05:31:16 AM
Old 07-07-2008
Code:
echo 123456 789 ABC DEF | sed "s/ //g"

This might help u!

Last edited by radoulov; 07-07-2008 at 06:43 AM.. Reason: added code tags
 

10 More Discussions You Might Find Interesting

1. Solaris

spaces trimming while assigning to a variable

Hi my lovely friends, Im writing one pgm in which i trying to assign some values like $var='Jun 6' but if i do echo of this $var will trim the spaces expect one space. $echo $var $Jun 6 But if var='Jun 28', then this will works fine $echo $var $Jun 28 this is required to exctract... (2 Replies)
Discussion started by: Lokesha
2 Replies

2. Shell Programming and Scripting

trimming white spaces

I have a variable that calls in a string from txt file. Problem is the string comes with an abundance of white spaces trailing it. Is there any easy way to trim the tailing white spaces off at the end? Thanks in advance. (9 Replies)
Discussion started by: briskbaby
9 Replies

3. UNIX for Advanced & Expert Users

trimming zeros

Hi, I want to trim +with leading zero's with amount fields.I know using awk for trimming leading zeros with +,but I want get the entire row itself. cat file_name |awk -F " " '{printf "%14.4f%f\n",$4}' ex: 10 xyz bc +00000234.4500 20 yzx foxic +002456.000 Expexted 10 xyz bc... (3 Replies)
Discussion started by: mohan705
3 Replies

4. Shell Programming and Scripting

trimming lines

hi have output as i have trim of lines before CREATE statement and lins after last ")" any idea how to achieve it ? (3 Replies)
Discussion started by: crackthehit007
3 Replies

5. Shell Programming and Scripting

trimming out spaces in solaris

friends, I have a script in solaris 10 SPARC system which is like this date '+Time: %m/%d/%y %H:%M:%S' echo " GDBRR GDLRR GDBWR GDLWR GDRRR GDRWR " sar -b 10 10 |/usr/xpg4/bin/awk '!/Average/ && !/SunOS/ && !/bread/ {$1="";T=$2;T1=$3;T2=$5;T3=$6;T4=$8;T5=$9}{print(T"\t",... (1 Reply)
Discussion started by: achak01
1 Replies

6. Shell Programming and Scripting

Trimming output

I'm trying to parse an output log and I've managed to reduce the output to the lines I need. But I'm having trouble pulling out only the info I'm interested in. The output is 40+ lines and here is a sample Installing AppFresh 0.8.5.pkg from ./InstallerFiles/CustomPKG/26 (26) Installing... (2 Replies)
Discussion started by: kaltekar
2 Replies

7. Shell Programming and Scripting

trimming sequences

My file looks like this: But I would like to 'trim' all sequences to the same lenght 32 characters, keeping intact all the identifier (>GHXCZCC01AJ8CJ) Would it be possible to use awk to perform this task? (2 Replies)
Discussion started by: Xterra
2 Replies

8. Shell Programming and Scripting

How can I stop the unix script from trimming extra spaces?

I have a file which contains certain records about users. the row length is always fixed to 205 characters. Now I want to read each record line from the file, substring some portion out of it and put into another file. But I have observed that my script is trimming the extra spaces I have used for... (4 Replies)
Discussion started by: Pramit
4 Replies

9. Shell Programming and Scripting

Trimming spaces from a variable

Hi guys, when I take substring of a particular data using this command var=substr($0,11,10) it comes with spaces, when I am trying to trim the spaces it is not allowing me to do that. Can you please help me out on that. As I have to reverse the output of the variable also. ---------- Post... (0 Replies)
Discussion started by: manish8484
0 Replies

10. Shell Programming and Scripting

Trimming Spaces in Unix

Hi All, I am using following script to name the file base of some values #!/bin/sh sourcefile=$1 awk ' BEGIN{ n = 1; name = "FILEFILE12" n ".txt"; } { if (substr($0,1,10) == "FILEFILE12") { close (name) n++ a = substr($0,11,10); b = substr($0,21,5); name = b "_Src_" a ".txt" }... (6 Replies)
Discussion started by: manish8484
6 Replies
NEWLOCALE(3)						     Linux Programmer's Manual						      NEWLOCALE(3)

NAME
newlocale, freelocale - create, modify, and free a locale object SYNOPSIS
#include <locale.h> locale_t newlocale(int category_mask, const char *locale, locale_t base); void freelocale(locale_t locobj); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): newlocale(), freelocale(): Since glibc 2.10: _XOPEN_SOURCE >= 700 Before glibc 2.10: _GNU_SOURCE DESCRIPTION
The newlocale() function creates a new locale object, or modifies an existing object, returning a reference to the new or modified object as the function result. Whether the call creates a new object or modifies an existing object is determined by the value of base: * If base is (locale_t) 0, a new object is created. * If base refers to valid existing locale object (i.e., an object returned by a previous call to newlocale() or duplocale(3)), then that object is modified by the call. If the call is successful, the contents of base are unspecified (in particular, the object referred to by base may be freed, and a new object created). Therefore, the caller should ensure that it stops using base before the call to newlo- cale(), and should subsequently refer to the modified object via the reference returned as the function result. If the call fails, the contents of base remain valid and unchanged. If base is the special locale object LC_GLOBAL_LOCALE (see duplocale(3)), or is not (locale_t) 0 and is not a valid locale object handle, the behavior is undefined. The category_mask argument is a bit mask that specifies the locale categories that are to be set in a newly created locale object or modi- fied in an existing object. The mask is constructed by a bitwise OR of the constants LC_ADDRESS_MASK, LC_CTYPE_MASK, LC_COLLATE_MASK, LC_IDENTIFICATION_MASK, LC_MEASUREMENT_MASK, LC_MESSAGES_MASK, LC_MONETARY_MASK, LC_NUMERIC_MASK, LC_NAME_MASK, LC_PAPER_MASK, LC_TELE- PHONE_MASK, and LC_TIME_MASK. Alternatively, the mask can be specified as LC_ALL_MASK, which is equivalent to ORing all of the preceding constants. For each category specified in category_mask, the locale data from locale will be used in the object returned by newlocale(). If a new locale object is being created, data for all categories not specified in category_mask is taken from the default ("POSIX") locale. The following preset values of locale are defined for all categories that can be specified in category_mask: "POSIX" A minimal locale environment for C language programs. "C" Equivalent to "POSIX". "" An implementation-defined native environment corresponding to the values of the LC_* and LANG environment variables (see locale(7)). freelocale() The freelocale() function deallocates the resources associated with locobj, a locale object previously returned by a call to newlocale() or duplocale(3). If locobj is LC_GLOBAL_LOCALE or is not valid locale object handle, the results are undefined. Once a locale object has been freed, the program should make no further use of it. RETURN VALUE
On success, newlocale() returns a handle that can be used in calls to duplocale(3), freelocale(), and other functions that take a locale_t argument. On error, newlocale() returns (locale_t) 0, and sets errno to indicate the cause of the error. ERRORS
EINVAL One or more bits in category_mask do not correspond to a valid locale category. EINVAL locale is NULL. ENOENT locale is not a string pointer referring to a valid locale. ENOMEM Insufficient memory to create a locale object. VERSIONS
The newlocale() and freelocale() functions first appeared in version 2.3 of the GNU C library. CONFORMING TO
POSIX.1-2008. NOTES
Each locale object created by newlocale() should be deallocated using freelocale(). EXAMPLE
The program below takes up to two command-line arguments, which each identify locales. The first argument is required, and is used to set the LC_NUMERIC category in a locale object created using newlocale(). The second command-line argument is optional; if it is present, it is used to set the LC_TIME category of the locale object. Having created and initialized the locale object, the program then applies it using uselocale(3), and then tests the effect of the locale changes by: 1. Displaying a floating-point number with a fractional part. This output will be affected by the LC_NUMERIC setting. In many European- language locales, the fractional part of the number is separated from the integer part using a comma, rather than a period. 2. Displaying the date. The format and language of the output will be affected by the LC_TIME setting. The following shell sessions show some example runs of this program. Set the LC_NUMERIC category to fr_FR (French): $ ./a.out fr_FR 123456,789 Fri Mar 7 00:25:08 2014 Set the LC_NUMERIC category to fr_FR (French), and the LC_TIME category to it_IT (Italian): $ ./a.out fr_FR it_IT 123456,789 ven 07 mar 2014 00:26:01 CET Specify the LC_TIME setting as an empty string, which causes the value to be taken from environment variable settings (which, here, specify mi_NZ, New Zealand Mori): $ LC_ALL=mi_NZ ./a.out fr_FR "" 123456,789 Te Paraire, te 07 o Pout-te-rangi, 2014 00:38:44 CET Program source #define _XOPEN_SOURCE 700 #include <stdio.h> #include <stdlib.h> #include <locale.h> #include <time.h> #define errExit(msg) do { perror(msg); exit(EXIT_FAILURE); } while (0) int main(int argc, char *argv[]) { char buf[100]; time_t t; size_t s; struct tm *tm; locale_t loc, nloc; if (argc < 2) { fprintf(stderr, "Usage: %s locale1 [locale2] ", argv[0]); exit(EXIT_FAILURE); } /* Create a new locale object, taking the LC_NUMERIC settings from the locale specified in argv[1] */ loc = newlocale(LC_NUMERIC_MASK, argv[1], (locale_t) 0); if (loc == (locale_t) 0) errExit("newlocale"); /* If a second command-line argument was specified, modify the locale object to take the LC_TIME settings from the locale specified in argv[2]. We assign the result of this newlocale() call to 'nloc' rather than 'loc', since in some cases, we might want to preserve 'loc' if this call fails. */ if (argc > 2) { nloc = newlocale(LC_TIME_MASK, argv[2], loc); if (nloc == (locale_t) 0) errExit("newlocale"); loc = nloc; } /* Apply the newly created locale to this thread */ uselocale(loc); /* Test effect of LC_NUMERIC */ printf("%8.3f ", 123456.789); /* Test effect of LC_TIME */ t = time(NULL); tm = localtime(&t); if (tm == NULL) errExit("time"); s = strftime(buf, sizeof(buf), "%c", tm); if (s == 0) errExit("strftime"); printf("%s ", buf); /* Free the locale object */ freelocale(loc); exit(EXIT_SUCCESS); } SEE ALSO
locale(1), duplocale(3), setlocale(3), uselocale(3), locale(5), locale(7) COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. Linux 2017-09-15 NEWLOCALE(3)
All times are GMT -4. The time now is 07:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy