Problem with echo for var, padded with spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with echo for var, padded with spaces
# 1  
Old 05-26-2005
Problem with echo for var, padded with spaces

While concatenating 2 values, one which expanded to fixed width & other not, I am not getting value expanded as fixed width.
Following is script for the same :

#!/bin/sh

var1="abc"
var2="def"
var1Fxd=`echo $var1 | awk '{printf("%-6s",$0)}'`
echo $var1Fxd""$var2

But, if I try -
echo "abc" | awk '{printf("%-6s",$0)}'

Then it is showing me correct result with 'abc' followed by 3 spaces.

Can anyone tell me, how I can I have var1Fxd & var2 on same echo command, since this o/p I am passing to a file.
# 2  
Old 05-26-2005
echo "$var1Fxd"$var2

And if you use a real shell, you can replace:
var1Fxd=`echo $var1 | awk '{printf("%-6s",$0)}'`

with:
typeset -L6 var1Fxd
var1Fxd=$var1
# 3  
Old 05-26-2005
Thanks it helps !!!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to echo a value of a var stored in another variable?

I'm writing a shell script in AIX and using ksh. I have a scenario where I have a variable A which stores $B. so when i echo "$A" it prints $B But I wish to print value stored in var b ie. \a\dir\res\ I wish to store \a\dir\res\ in a third variable C. later I want to cd into that path :... (1 Reply)
Discussion started by: simpltyansh
1 Replies

2. Ubuntu

problem with /var/mail directory

Hi, There is no "administrator" file in "/var/mail" directory........ can any one tell me what could be the reason for that?...and also how to resolve that??? Thanks, ~Kavi (4 Replies)
Discussion started by: kavi.mogu
4 Replies

3. Shell Programming and Scripting

Help with removing "echo-ed spaces"...

I have the following in a shell script myfilecount=`echo /dir1/dir2/file-sample* | wc -w` echo "Directory has $myfilecount files" The output looks like this: Directory has 540 files How can I remove the space between "has" and "540" so it looks more normal? Like this: ... (3 Replies)
Discussion started by: bbbngowc
3 Replies

4. Solaris

SVM Problem Regarding /var

Hi Guys! I am facing Problem with SVM I mention the problem below: I have Sunfire V210 machine and the partitions are as follows: Part Tag Flag Cylinders Size Blocks 0 root wm 0 - 6134 29.77GB (6135/0/0) 62429760 1 swap wu ... (1 Reply)
Discussion started by: sensation
1 Replies

5. Shell Programming and Scripting

Problem running var (with spaces) as command

I seem to be fighting bash's shell expansions.. I set this variable: CMD="export MVAR=\"1 2 3\"" if I try to run it, it is clear the shell is parsing along the spaces of the contents of MYVAR: > $CMD + export 'MYVAR="1' 2 '3"' + MYVAR='"1' -bash: export: `2': not a valid identifier... (3 Replies)
Discussion started by: bbw
3 Replies

6. Shell Programming and Scripting

help with echo command in reading blank spaces in aix

Hi, I have a test.txt and would like to put in a different file but while putting in the other file, blank spaces are missing. $ indicates blank spaces filename: test.txt: USA$$$840$$$$ Desired output USA$$$840$$$$ Current output as per the following code. while read j; do... (3 Replies)
Discussion started by: techmoris
3 Replies

7. Shell Programming and Scripting

ftp var for filename with spaces

Hello all, I am having difficulties writing an ftp script to retrieve a file via get using a variable name to pass the file name. I know the name of the file I am going to retrieve, this file name has embedded spaces and punctuation in the name itself. If I interactively use the get and I... (10 Replies)
Discussion started by: gio001
10 Replies

8. Shell Programming and Scripting

Problem regarding Sed/Echo/Var Init

Greetings, I've visited this forums for a long time and normally got an right answer but this time my problem doesn't seem to go away. What I'm trying to do is the following: VAR="\n\nline1\nline2\nline3\nline4\nline5\nline6\nline7\n\n" (The count of newlines is varying!) If I echo this i... (3 Replies)
Discussion started by: ph1l
3 Replies

9. Shell Programming and Scripting

Store command in a Var problem

Hi! I strated to script since 1 month and I don't have much expirience but this thing here is strange I have a script where I want to store a svn command in a var to check it later so it's like this #!/bin/sh list=`ssh itadmin@192.168.1.200 "ls /home/svn"` # this stores the list of... (13 Replies)
Discussion started by: ruben.rodrigues
13 Replies

10. UNIX for Dummies Questions & Answers

echo is suppressing multiple spaces.How to avoid it

I am reading a file and copying selected lines from the file into another using echo. For eg: while read line do if ((some logic to determine whether I need to copy the current line to another file)) then echo $line > tempfile fi done<srcfile The problem I have is the data in the file... (1 Reply)
Discussion started by: prathima
1 Replies
Login or Register to Ask a Question