Variable has spaces around the string, need to remove them

Hi all, I'm a newbie to the Linux world and I got a couple of shell script questions:

(1) How do combine two variables and make it equal to a third variable? For example, I got a variable $A=FirstName, $B=LastName, and I want to combine the variable into one variable so when you echo the final variable, it looks like "Joe Smith", not "JoeSmith". What is the exact syntax for that? (Im using bash shell script)

(2) Down below is a script that I executed called testfile. When I execute, note the bold face item where there is a space between the numbers 516 and 10757. How can I get rid of the space before and after those two numbers? The string I need to output is a little bit tricky...Im puzzled on this one.

Thanks in advance for your response.

[root@mymachine mikey]# sh testfile
Oct
516
10757
Mycmd1 is next
get "$$ BID=# 516 " RPT132.20051012
get "$$ BID=# 10757 " RPT590.20051012

my script looks like this:

[root@mymachine mikey]# cat testfile
# Set date
curdate=`date +%Y%m%d`
mondate="Oct 12"
#daydate=`date +%d`
#totaldate=$mondate . $daydate
mondate=Oct
daydate=12
#totaldate=$mondate + $daydate
cat filelist.txt | grep -i "Oct 12" | grep -i rpt132 > mike1.txt
cat filelist.txt | grep -i "Oct 12" | grep -i rpt590 > mike2.txt

echo $mondate
#
# Strip the Batch ID from the listing of the file
#rm mike1.txt
#rm mike2.txt
batchid1=`cat mike1.txt | cut -nb 27-36`
echo $batchid1
batchid2=`cat mike2.txt | cut -nb 27-36`
echo $batchid2
echo "Mycmd1 is next"
mycmd1="get \"\$\$ BID=#$batchid1\" RPT132.$curdate"
echo $mycmd1
mycmd2="get \"\$\$ BID=#$batchid2\" RPT590.$curdate"
echo $mycmd2
#
#

[root@mymachine mikey]#

For you first question :
var1="Joe"
var2="Smith"
echo ${var1}" "${var2}

result is "Joe Smith"

I don't understand your second question...

First - the UUoC patrol....

cat filelist.txt | grep -i "Oct 12" | grep -i rpt132 > mike1.txt

better written as

grep -i "Oct 12" filelist.txt | grep -i rpt132 > mike1.txt

and

batchid1=`cat mike1.txt | cut -nb 27-36`

better written as

batchid1=`cut -nb 27-36 mike1.txt`

Could the second problem be due to the fact that mike1.txt contains white space?

try:

batchid1=`cut -nb 27-36 mike1.txt | sed 's/ //'`

Else; post mike1.txt so we can see the input.

Cheers
ZB

Hi zazzybob.

Here are my two scripts I am reading from.

[mikey@mymachine mikey]$ cat mike1.txt
-r--r--r-- 1 mikftp 516 508 Oct 12 07:11 rpt132
[mikey@mymachine mikey]$ cat mike2.txt
-r--r--r-- 1 mikftp 10757 58 Oct 12 07:11 rpt590
[mikey@mymachine mikey$]

Thanks for reviewing it for me. :slight_smile:

mikey20, look at what you posted. Those aren't scripts.