echo is suppressing multiple spaces.How to avoid it


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers echo is suppressing multiple spaces.How to avoid it
# 1  
Old 04-29-2008
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 is:

12345 bjhjhd sdjkfhkdsfjh fdsfsf sdfds
43214 hjhkjkj kjhkjhkhjhjknds jkjnkjnk jkokjlkj
djjdfff sdfsdffdfgfgdfgfdf sdfsfsdfsgv dfsdfv

each line has multiple spaces.

After running the above piece of code tempfile is created as:
12345 bjhjhd sdjkfhkdsfjh fdsfsf sdfds
43214 hjhkjkj kjhkjhkhjhjknds jkjnkjnk jkokjlkj
djjdfff sdfsdffdfgfgdfgfdf sdfsfsdfsgv dfsdfv

echo is suppressing multiple spaces.. how to avoid it?

Can you please help!
Thanks in advance!
# 2  
Old 04-29-2008
Code:
echo "$line"

 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to avoid the spaces?

Hi I have a script which runs the isql command and takes the output in a xls file. Is there a way to trim the spaces(leading and trailing) from all the values in the column of the xls sheet? (6 Replies)
Discussion started by: Sharma331
6 Replies

2. Shell Programming and Scripting

Avoid multiple emails being sent - Counter, Loop?

Hello, I have currently coded a bash script below in which it does the following: # Archives compressed file from another location. Basically it moves *.gz files to another location. The script also sends an email whenever a new compressed file is placed. This is the issue that i... (5 Replies)
Discussion started by: Wizard_1979
5 Replies

3. Shell Programming and Scripting

How to avoid multiple ssh -o StrictHostKeychecking=no?

How do i avoid multiple ssh -o StrictHostKeychecking=no in the below script. if then echo " Please mention the server name after the script" elif ssh -o StrictHostKeychecking=no $1 "" 2> /dev/null then ver=`ssh -o StrictHostKeychecking=no $1 "cat /abc/def/version" 2> /dev/null` env=`ssh... (3 Replies)
Discussion started by: NarayanaPrakash
3 Replies

4. Shell Programming and Scripting

How to avoid the truncating of multiple spaces into a single space while reading a line from a file?

consider the small piece of code while read line do echo $line done < example content of example file sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the output is like sadasdasdasdsa erwerewrwr ergdgdfgf rgerg erwererwr the... (4 Replies)
Discussion started by: Kesavan
4 Replies

5. 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

6. Shell Programming and Scripting

Avoid script running multiple times by filelock

Sometimes we need a single instance of a script to run at a time. Meaning, the script itself should detects whether any instances of himself are still running and act accordingly. When multiple instances of one script running, it’s easy to cause problems. I’ve ever seen that about 350 instances... (4 Replies)
Discussion started by: edenCC
4 Replies

7. Shell Programming and Scripting

How to avoid multiple while loop?

Hi, How can I avoid multiple 'cat while read ....? in my script. In my script, I am taking the inputs from the temp text file and doing the ( cat while read input do ... ... done ) task and deleting later. I know it'll raise the perfomance issue. How to avoid this? (2 Replies)
Discussion started by: sharif
2 Replies

8. Shell Programming and Scripting

echo omits slash - how to avoid

Hi, I have a file which contains as follows, a.tmp Test \13\ Hello When i read the file and print the ouput using echo, "\" is not coming. How to avoid it. here goes the script a.sh ----- while read line do echo $line done < a.tmp Output is: Test 13 (3 Replies)
Discussion started by: tc.omkumar
3 Replies

9. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: videsh77
2 Replies
Login or Register to Ask a Question