Operating System - HP-UX
1833788 Members
2173 Online
110063 Solutions
New Discussion

How can i add an space at the end of the word ...?

 
SOLVED
Go to solution
Manuales
Super Advisor

How can i add an space at the end of the word ...?

hi ..

v=hi
i want that v="hi " i mean a space at the end of the word ... how can i do that?
i tried
V=`echo $v `
but it did not work .. :(

thanks..
6 REPLIES 6
James R. Ferguson
Acclaimed Contributor
Solution

Re: How can i add an space at the end of the word ...?

Hi Manuales:

Use formatted printing:

# v="hi"
# printf "%-s \n" $v | cat -etv

...and you will see the space before the neline ($).

p.s. I added some more commentary to your thread here:

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=1115881

Regards!

...JRF...
Hein van den Heuvel
Honored Contributor

Re: How can i add an space at the end of the word ...?

We just discussed that in a prior topic of yours.
Those double quotes!
You gotta know when to hold them, when to fold them!

$ v=hi
$ vv=$v" "
$ vvv="hi "
$ echo "==$v==$vv==$vvv=="
==hi==hi ==hi ==

free advice...
bracket variable names to allow arbitrary strings to be glues to them

$ x="${v}test"

Hein.


Hein.
Manuales
Super Advisor

Re: How can i add an space at the end of the word ...?

THHHHAAAAAAAAANKKKKKKKKKKSS

IT WORKED ...

$ printf "%-s \n" $v | cat -etv
hi $
$ V=`printf "%-s \n" $v | cat -etv`
$ echo $V
hi $
$ echo $V | sed 's/\$//g'
hi
$ echo $V | sed 's/\$//g' | wc -w
1
$ echo $V | sed 's/\$//g' | wc -s
wc: illegal option -- s
usage: wc [-c|-m] [-lw] [name ...]
$ echo $V | sed 's/\$//g' | wc -c
4


Thanks a lot !!!! :)
Manuales
Super Advisor

Re: How can i add an space at the end of the word ...?

Hi ..
i have other doubt ..


$ m=`echo $Z | sed 's/\$//g'`
$ echo $m
hi $
$

why can i not to replace $ by nothing? when i'm using sed command ..

please let me know

Manuales
Super Advisor

Re: How can i add an space at the end of the word ...?

ok ok

i already understood ..

i have only to use the following ...

printf "%-s \n" $v


thanks !!!!!
Ralph Grothe
Honored Contributor

Re: How can i add an space at the end of the word ...?

Sigh, only mundane shell talks.
From the subject line I was excited to witness a phylosophical dispute about infinity, eternity and beyond here.
Madness, thy name is system administration