Leading spaces of variable removed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Leading spaces of variable removed
# 1  
Old 08-29-2008
Leading spaces of variable removed

Code:
#!/bin/bash

TESTVAR="     5spaces"
echo $TESTVAR

Code:
hostame:~# ./test.sh
5spaces

The leading spaces from my variable are removed when the content is echo'd. I am trying to make some tabular data.

`echo -e` also fails.

Any suggestions?
# 2  
Old 08-29-2008
Code:
echo "$TESTVAR"

...the variable put inside double-quotes will preserve spaces
# 3  
Old 08-29-2008
Works great. Thanks!
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 remove leading and trailing spaces for variable in shell script?

Hi I have variable named tablename. The value to tablename variable has leading and trailing white spaces. How to remove the leading and training white spaces and write the value of the tablename without space to a file using shell script. ( for e.g. tablename= yyy ) INPUT ... (10 Replies)
Discussion started by: pottic
10 Replies

2. Shell Programming and Scripting

Trying to remove leading spaces

OS : RHEL 6.7 Shell : bash I am trying to remove the leading the spaces in the below file $ cat pattern2.txt hello1 hello2 hello3 hello4 Expected output is shown below. $ cat pattern2.txt hello1 hello2 hello3 hello4 (2 Replies)
Discussion started by: John K
2 Replies

3. Shell Programming and Scripting

Leading white spaces

Hi, I am having problem in deleting the leading spaces:- cat x.csv baseball,NULL,8798765,Most played baseball,NULL,8928192,Most played baseball,NULL,5678945,Most played cricket,NOTNULL,125782,Usually played cricket,NOTNULL,678921,Usually played $ nawk 'BEGIN{FS=","}!a... (2 Replies)
Discussion started by: scripter12
2 Replies

4. Shell Programming and Scripting

Removing leading spaces from the variable value.

Hi All, I am trying to replace the value of a xml tag with a new one. But, the existing value in the xml contain leading spaces and I tried to remove that with different sed commands but all in vain. For replacing the value I wrote the command in BOLD letters below: bash-3.00$... (3 Replies)
Discussion started by: khedu
3 Replies

5. Shell Programming and Scripting

Not able to remove leading spaces

Hi Experts, In a file tht i copied from the web , i am not able to remove the leading white spaces. I tried the below , none of them working . I opened the file through vi to check for the special characters if any , but no such characters found. Your advice will be greatly appreciated. sed... (5 Replies)
Discussion started by: panyam
5 Replies

6. Shell Programming and Scripting

Overwriting the leading spaces in NAWK

I have a file 1 1 40421 120 18421 112h 019 6 10335 03 1 1 40421 120 18422 124h 055 6 10335 03 I have wriiten a nawk statement nawk '$5 ~ "18421" {sub($7,"0190"print}' old.txt I am getting the output as 1 1 40421 120 18421 112h 0190 6 10335... (5 Replies)
Discussion started by: prav076
5 Replies

7. Shell Programming and Scripting

remove leading spaces from a line

Hi friends I need some help, I have a file which looks as follows TEMP 014637065 014637065 517502 517502 RTE 517502 517502 RTE AWATER_TEST 12325 23563 588323 2323 5656 32385 23235635 ANOTHER_TEST 12 5433 FTHH 5653 833 TEST 123 123 3235 5353 353 53 35 353 535 3 YTERS GJK JKLS ... (6 Replies)
Discussion started by: lijojoseph
6 Replies

8. UNIX for Dummies Questions & Answers

Stripping leading spaces on right justified name

I have a name field in a file which is right justified (yep - its true). I need to strip the leading spaces from the field and write the name out left justified. Again, I think I need to use a sed or awk command but so far, my results are at best disappointing. Thank you in advance from a UNIX... (2 Replies)
Discussion started by: Marcia P
2 Replies

9. Shell Programming and Scripting

Strip leading and trailing spaces only in a shell variable with embedded spaces

I am trying to strip all leading and trailing spaces of a shell variable using either awk or sed or any other utility, however unscuccessful and need your help. echo $SH_VAR | command_line Syntax. The SH_VAR contains embedded spaces which needs to be preserved. I need only for the leading and... (6 Replies)
Discussion started by: jerardfjay
6 Replies

10. Shell Programming and Scripting

Leading and Trailing Spaces

Hi, how to i remove leading and trailing spaces from a line? the spaces can be behind or in front of any field or line example of a line in the input data: Amy Reds , 100 , /bin/sh how to i get it to be: Amy Read,100,/bin/sh i saw something on this on the Man pages for AWK... (7 Replies)
Discussion started by: sleepster
7 Replies
Login or Register to Ask a Question