how to merge two variable in one variable with space between them?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to merge two variable in one variable with space between them?
# 1  
Old 12-15-2007
how to merge two variable in one variable with space between them?

Dear all

I had two separate variable. Now i want to make them merge into one new variable with space between them. Kindly suggest me.

var1=dec 15
var2=10

i want var3=dec 15 10


My main aim is as below:

op of date command:
>date
>Sat Dec 15 10:17:35 IST 2007

i want only Dec 15 10: in new variable.

Suggest me possible ways.

Thanks in advance

regards
jaydeep
# 2  
Old 12-15-2007
var3="$var1 $var2"

or

var3=$var1\ $var2
# 3  
Old 12-15-2007
Quote:
Originally Posted by jaydeep_sadaria
Dear all

I had two separate variable. Now i want to make them merge into one new variable with space between them. Kindly suggest me.

var1=dec 15
var2=10

i want var3=dec 15 10


My main aim is as below:

op of date command:
>date
>Sat Dec 15 10:17:35 IST 2007

i want only Dec 15 10: in new variable.

Suggest me possible ways.

Thanks in advance

regards
jaydeep
Code:
val=$(date "+%b %d %H")

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Space in PATH variable

Hi All, I did a review of some threads to see if someone had come across this problem. My system is an oracle virtual box solaris 10 installed on a windows 10 system. Right now I am learning scripting and am just playing with the env variables. I am trying to update the PATH to... (9 Replies)
Discussion started by: bdby
9 Replies

2. Shell Programming and Scripting

How to merge variable data from another file into specific place?

Hello, I'm trying to create multiple commands using a variable input from another file but am not getting any successful results. Basically, file1.txt contains multiple lines with single words: <file1.txt> yellow blue black white I want to create multiple echo commands with these... (8 Replies)
Discussion started by: demmel
8 Replies

3. Shell Programming and Scripting

Merge output of 2 commands into variable

I am extracting two pieces of information from the following file: /proc/cpuinfo, that I need to merge into one report. The first command: grep -i processor /proc/cpuinfo | awk '{print $1$2,$3}' yields: processor: 0 processor: 1 processor: 2 processor: 3 The second command: grep -i... (4 Replies)
Discussion started by: jamarsh
4 Replies

4. UNIX for Dummies Questions & Answers

awk for variable with a space

Hi experts, why does $ echo "one two three" | awk '{$3="my tree"; print $0}' one two my tree work, but $ var="my tree" $ echo "one two three" | awk '{$3="'$var'"; print $0}' awk: {$3="my awk: ^ unterminated string does not work? How can the variable tha contains a space be... (2 Replies)
Discussion started by: GermanicGalore
2 Replies

5. Emergency UNIX and Linux Support

Merge Static and dynamic parts in variable declaration

Dear Unix experts Moved from "Shell Programming and Scripting " I want to define a variable which contains dynmic and static part, daynamic part is the first field. Sample of data dddd aaaa sssss 12345 ssss 2323 234234 4242 dddd 3223 34234 54353 ssss 24234 3434 42342 dddd rwrw 423423... (2 Replies)
Discussion started by: yahyaaa
2 Replies

6. Shell Programming and Scripting

Merge Static and dynamic parts in variable declaration

Dear Unix experts I want to define a variable which contains dynmic and static part, daynamic part is the first field. Sample of data dddd aaaa sssss 12345 ssss 2323 234234 4242 dddd 3223 34234 54353 ssss 24234 3434 42342 dddd rwrw 423423 werwer nawk 'BEGIN {FS=" "}{... (4 Replies)
Discussion started by: yahyaaa
4 Replies

7. Shell Programming and Scripting

How to define a variable with variable definition is stored in a variable?

Hi all, I have a variable say var1 (output from somewhere, which I can't change)which store something like this: echo $var1 name=fred age=25 address="123 abc" password=pass1234 how can I make the variable $name, $age, $address and $password contain the info? I mean do this in a... (1 Reply)
Discussion started by: freddy1228
1 Replies

8. Shell Programming and Scripting

Using Variable With Space In It?

Hey , I'm new to Bash and am having trouble with writing a script. I have a variable and want to use it to create a tar file, but, I am having problems. Can anyone tell me what I'm doing wrong? filestr=`date "+%y-%m-%d %H.%M.%S"`.tar tar -cvf $filestr test.txt So, basically,... (3 Replies)
Discussion started by: beefeater267
3 Replies

9. Shell Programming and Scripting

appending space to variable

Hi I need to write a script where there the user enters 3 input parameter variable number the program should ask the user left or right if it is left , the number specified that many spaces should be added to the value in front of the value and saved in the samee variable itself and if it is... (5 Replies)
Discussion started by: viv1
5 Replies

10. Shell Programming and Scripting

space in variable

Hi, How to check if a variable is having spaces or empty in shell scripts. Please help esham (4 Replies)
Discussion started by: esham
4 Replies
Login or Register to Ask a Question