Sponsored Content
Top Forums Shell Programming and Scripting White spaces issue with shell variables Post 302591093 by madhu_1126 on Wednesday 18th of January 2012 01:19:40 PM
Old 01-18-2012
White spaces issue with shell variables

Hi all,

I've a requirement as below

Source file src.txt sample data:

A<10 white spaces>B12<5 white spaces>C<17 white spaces>
A1<5 white spaces>B22<5 white spaces>C13<17 white spaces>

when I'm fetching a record from this file into a shell variable like below:
vRec=`head -1 src.txt |tail -1`

the record stored in variable as below
echo $vRec
A<single white space>B12<single white space>C<no white spaces>

Hence all the white spaces in between characters are trimmed to a single white space and all the white spaces at the end of the record are trimmed.

Please let me know if there is any way to retain these spaces in the unix shell variable.

Regards,
Madhu
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

deleting white spaces

How would I delete white spaces in a specified file? Also, I'd like to know what command I would use to take something off a regular expression, and put it onto another. ie. . . . expression1 <take_off> . . . expression2 (put here) . . . Any help would be great, thanks! (10 Replies)
Discussion started by: cary530
10 Replies

2. Shell Programming and Scripting

delete white spaces

hi all... i have the next question: i have a flat file with a lot of records (lines). Each record has 10 fields, which are separated by pipe (|). My problem is what sometimes, in the first record, there are white spaces (no values, nothing) in the beginning of the record, like this: ws ws... (2 Replies)
Discussion started by: DebianJ
2 Replies

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

4. Shell Programming and Scripting

Two or more white spaces in string

Hi, Can anybody suggest me how to combine two strings with two or more white spaces and assign it to a variable? E.g. first=HAI second=HELLO third="$first $second" # appending strings with more than one white spaces echo $third this would print HAI HELLO Output appears... (2 Replies)
Discussion started by: harish_oty
2 Replies

5. Shell Programming and Scripting

ksh: removing all white spaces

'String' file contains the following contents, D11, D31, D92, D29, D24, using ksh, I want to remove all white spaces between characters no matter how long the string is. Would you please give me some help? (1 Reply)
Discussion started by: yoonius
1 Replies

6. UNIX for Dummies Questions & Answers

handling white spaces with getopt

Hi I'm trying to ensure that I have catered for all situations with my getopt cases. One other situation I want to cover is should the user enter the script without any preceding arguments eg: ./script_eg I need the script to the direct the user to the helpfile I have tried... (3 Replies)
Discussion started by: ladyAnne
3 Replies

7. Shell Programming and Scripting

Leading white spaces

Hi, I am having problem in deleting the leading spaces:- cat x.csv baseball,NULL,8798765,Most played baseball,NULL,8928192,Most played baseball,NULL,5678945,Most played cricket,NOTNULL,125782,Usually played cricket,NOTNULL,678921,Usually played $ nawk 'BEGIN{FS=","}!a... (2 Replies)
Discussion started by: scripter12
2 Replies

8. Shell Programming and Scripting

Spaces in filenames located in variables in shell.

Greetings. I am trying to do a script that will do some file copying for me. Unfortunately I have spaces in the directory names (which I cannot change) and the result is someone hard to achieve in shell scripts. I have searched everywhere on the web but does not manage to find the answer to... (3 Replies)
Discussion started by: Mr.Glaurung
3 Replies

9. UNIX for Dummies Questions & Answers

[Solved] Help with using tr - Removing white spaces

Hi, I have a file that contains whitespaces with spaces and spaces and tabs on each line and am wanting to remove the whitespaces. My version of sed is one that does not recognize \t etc. The sed and awk one-liners below that I found via Google both does not work. So my next best... (3 Replies)
Discussion started by: newbie_01
3 Replies

10. Shell Programming and Scripting

Shell command to Strip white spaces at specific location

Hello, I have a Comma separated input file with one of the sample records as below: -9223372036854477528,"834","834003325515BXNI00101012013C","5","PLAN_VALUE","PPO, General Cable","C",20130101,99991231,"A","2012-12-25-13.58.14.434000","ZPL2 ","2012-12-25-13.58.14.434000","ZPL2 ... (4 Replies)
Discussion started by: Praveenkulkarni
4 Replies
Tcl_GetInt(3)						      Tcl Library Procedures						     Tcl_GetInt(3)

__________________________________________________________________________________________________________________________________________________

NAME
Tcl_GetInt, Tcl_GetDouble, Tcl_GetBoolean - convert from string to integer, double, or boolean SYNOPSIS
#include <tcl.h> int Tcl_GetInt(interp, src, intPtr) int Tcl_GetDouble(interp, src, doublePtr) int Tcl_GetBoolean(interp, src, boolPtr) ARGUMENTS
Tcl_Interp *interp (in) Interpreter to use for error reporting. const char *src (in) Textual value to be converted. int *intPtr (out) Points to place to store integer value converted from src. double *doublePtr (out) Points to place to store double-precision floating-point value converted from src. int *boolPtr (out) Points to place to store boolean value (0 or 1) converted from src. _________________________________________________________________ DESCRIPTION
These procedures convert from strings to integers or double-precision floating-point values or booleans (represented as 0- or 1-valued integers). Each of the procedures takes a src argument, converts it to an internal form of a particular type, and stores the converted value at the location indicated by the procedure's third argument. If all goes well, each of the procedures returns TCL_OK. If src does not have the proper syntax for the desired type then TCL_ERROR is returned, an error message is left in the interpreter's result, and noth- ing is stored at *intPtr or *doublePtr or *boolPtr. Tcl_GetInt expects src to consist of a collection of integer digits, optionally signed and optionally preceded by white space. If the first two characters of src after the optional white space and sign are "0x" then src is expected to be in hexadecimal form; otherwise, if the first such character is "0" then src is expected to be in octal form; otherwise, src is expected to be in decimal form. Tcl_GetDouble expects src to consist of a floating-point number, which is: white space; a sign; a sequence of digits; a decimal point; a sequence of digits; the letter "e"; a signed decimal exponent; and more white space. Any of the fields may be omitted, except that the digits either before or after the decimal point must be present and if the "e" is present then it must be followed by the exponent number. Tcl_GetBoolean expects src to specify a boolean value. If src is any of 0, false, no, or off, then Tcl_GetBoolean stores a zero value at *boolPtr. If src is any of 1, true, yes, or on, then 1 is stored at *boolPtr. Any of these values may be abbreviated, and upper-case spellings are also acceptable. KEYWORDS
boolean, conversion, double, floating-point, integer Tcl Tcl_GetInt(3)
All times are GMT -4. The time now is 05:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy