Sponsored Content
Top Forums Shell Programming and Scripting How to insert a space and assign the value to another variable? Post 302923577 by prvnrk on Monday 3rd of November 2014 04:09:35 PM
Old 11-03-2014
How to insert a space and assign the value to another variable?

Hello,

I need to insert a space between 2 strings. I used many techniques and all of them worked but when I assign the value to another variable then the inserted space vanishes, strange! Please advise.

Code:
# dat=`date |awk '{print $2,$3}'`
# echo $dat
Nov 3

The above is perfectly fine. Now

Code:
# echo ${dat}|sed "s/ /  /g"
Nov  3
#

The above also is perfectly fine. Now if I assign the same output to another variable the extra space vanished.

Code:
# dat2=`echo ${dat}|sed "s/ /  /g"`
# echo $dat2
Nov 3
#

Please advise how to retain the extra space in the new variable. Sorry if its a basic question but I never noticed such things.

TIA
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

2. Shell Programming and Scripting

Insert space between two words

Hi, I need to insert space between words on my output in UNIX other than the single space given by the space bar on my keyboard, e.g when are you going. (There should be 4 spaces between each of these words) rather than when are you going Can anyone help me with... (3 Replies)
Discussion started by: divroro12
3 Replies

3. Shell Programming and Scripting

assign awk's variable to shell script's variable?

Dear All, we have a command output which looks like : Total 200 queues in 30000 Kbytes and we're going to get "200" and "30000" for further process. currently, i'm using : numA=echo $OUTPUT | awk '{print $2}' numB=echo $OUTPUT | awk '{print $5}' my question is : can I use just one... (4 Replies)
Discussion started by: tiger2000
4 Replies

4. Programming

Assign variable for INSERT INTO statement

Hello, Can anyone tell me that, How can I assign variable to shell script variable, which i need to use in INSERT INTO statement? my shell script variables are, EMPNAME=`regular expression` EMPID=`regular expression` EMPBDATE=`regular expression` Now through ksh script I am... (16 Replies)
Discussion started by: Poonamol
16 Replies

5. Shell Programming and Scripting

Shell assign variable to another variable

How can I assign a variable to an variable. IE $car=honda One way I can do it is export $car=honda or let $car=2323 Is there any other ways to preform this task (3 Replies)
Discussion started by: 3junior
3 Replies

6. Shell Programming and Scripting

Looking for help with script to assign all disk space to slice#0 on multiple disks of varying sizes

Hi Folks, I am trying to make a script to assign all diskspace to slice 0, on multiple sized disks. Since the disks are new they may need to be labelled also to avoid the error: Cannot get disk geometry Below is my code struggling with logic which doesn't seem to be producing the desired... (0 Replies)
Discussion started by: momin
0 Replies

7. Shell Programming and Scripting

Insert text space

I have the following texts in a .txt file, 22/02 23/02 24/02 25/02 26/02 Bike speed (kmph) 004 004 004 004 004 22/02 23/02 24/02 25/02 26/02 Bike speed (kmph) 004 007 007 007 011 I am trying to export it to .csv by doing cat nic.txt > nic.csv 22/02 23/02 are date and this has to... (7 Replies)
Discussion started by: nicolethomson
7 Replies

8. Shell Programming and Scripting

how to insert space in alphanumeric string

Hi everyone, I want help to insert space between digits and letters in a alphanumeric string. INPUT TRY234TER PHY1TYR EXPECTED OUTPUT TRY 234 TER PHY 1 TYR The lines always begin with the letters and the alphabets will be a three letter combination before and after the number. The... (2 Replies)
Discussion started by: kaav06
2 Replies

9. UNIX for Beginners Questions & Answers

Need to pass variable in a command and assign value to a variable

Hello All, Hope you're doing well ! I am trying below command to be passed in a shell script, header_date_14 is a variable and $1 is the name of a file I intend to pass as a command line argument, however command line argument is not being accepted. header_date_14=$(m_dump... (8 Replies)
Discussion started by: ektubbe
8 Replies

10. UNIX for Beginners Questions & Answers

How can I assign awk's variable to shell script's variable?

I have the following script, and I want to assign the output ($10 and $5) from awk to N and L: grdinfo data.grd | awk '{print $10,$5}'| read N L output from gridinfo data.grd is: data.grd 50 100 41 82 -2796 6944 0.016 0.016 3001 2461. where N and L is suppose to be 3001 and 100. I use... (8 Replies)
Discussion started by: geomarine
8 Replies
GETRUSAGE(3)								 1							      GETRUSAGE(3)

getrusage - Gets the current resource usages

SYNOPSIS
array getrusage ([int $who]) DESCRIPTION
This is an interface to getrusage(2). It gets data returned from the system call. PARAMETERS
o $who - If $who is 1, getrusage will be called with RUSAGE_CHILDREN. RETURN VALUES
Returns an associative array containing the data returned from the system call. All entries are accessible by using their documented field names. EXAMPLES
Example #1 getrusage(3) example <?php $dat = getrusage(); echo $dat["ru_nswap"]; // number of swaps echo $dat["ru_majflt"]; // number of page faults echo $dat["ru_utime.tv_sec"]; // user time used (seconds) echo $dat["ru_utime.tv_usec"]; // user time used (microseconds) ?> CHANGELOG
+--------+---------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------+ | 7.0.0 | | | | | | | This function is now supported on Windows. | | | | +--------+---------------------------------------------+ NOTES
Note On Windows getrusage(3) will only return the following members: o "ru_stime.tv_sec" o "ru_stime.tv_usec" o "ru_utime.tv_sec" o "ru_utime.tv_usec" o "ru_majflt" (only if $who is RUSAGE_SELF) o "ru_maxrss" (only if $who is RUSAGE_SELF) If getrusage(3) is called with $who set to 1 ( RUSAGE_CHILDREN), then resource usage for threads are collected (meaning that inter- nally the function is called with RUSAGE_THREAD). Note on BeOS 2000, only the following members are returned: o "ru_stime.tv_sec" o "ru_stime.tv_usec" o "ru_utime.tv_sec" o "ru_utime.tv_usec" SEE ALSO
Your system's man page on getrusage(2). PHP Documentation Group GETRUSAGE(3)
All times are GMT -4. The time now is 07:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy