Spaces getting trimmed off


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Spaces getting trimmed off
# 1  
Old 05-13-2008
Spaces getting trimmed off

Hi,
I have a K shell variable which is holding some long data and when i write the content of the variable to a file, its trimming off some of the intermediate spaces.

e.g: variable="BCMSGITADD81206 DOMTAR MULTI PURPOSE SALMON STKCS CTN 0
1387CTNL70 0008.500000011.0000000010.00000005.0000N020.00075.180000050.000005000
04000003NY00500 0100 163 000000 1 1 500 Sheets per Seal; Ream Sea
led; 3"

when i do
echo "$variable" >> file.txt

the file contains the data with some of the spaces trimmed off in between
If i have 11 spaces after BCMSGITADD81206 its becoming 7 and some other spaces also getting trimmed off...


Please give me suggestion what could be the cause for this.

Thanks
Vijay
# 2  
Old 05-13-2008
Perhaps they are not actually spaces, but tabs.

You can check using echo "$variable" | cat -vet which displays characters for what they really are.

Also, does the output of these two commands differ?

Code:
echo "$variable" | wc -c
wc -c < file.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Spaces

Input: TCAMPBMG0064X344F4E1 1 47552 85.280 557.600 11300 TCAMPBMG0064X352F8E1 1 61265 85.280 718.400 11463 TCAMPBMG0064X344F4E1 1 47552 85.280 557.600 11300 TCAMPBMG0064X352F8E1 1 61265 ... (2 Replies)
Discussion started by: satish1222
2 Replies

2. Shell Programming and Scripting

Folder name with spaces

Hello, When I give: rm -f /usr/local/tomcat/temp_img/\Images\ for\ UAT/0918-721-163-001-4C-P_04.jpg , the file is being deleted. I am trying to do the same in a script as follows: Step 1: A file named del.txt will have the following (list of files to be deleted):... (6 Replies)
Discussion started by: risshanth
6 Replies

3. Shell Programming and Scripting

Space being trimmed off

Hi All, I am facing a peculiar situation. I have an output from some commands as below # cat /export/home/FPPCCYHT | head -1 | cut -d"'" -f2 | cut -d"'" -f1 LLM10 01 0100:0240 If i assign this to a variable and then echo instead of 2 spaces only 1 space is appearing, meaning 1 space is being... (5 Replies)
Discussion started by: digitalrg
5 Replies

4. Shell Programming and Scripting

Removing blank spaces, tab spaces from file

Hello All, I am trying to remove all tabspaces and all blankspaces from my file using sed & awk, but not getting proper code. Please help me out. My file is like this (<b> means one blank space, <t> means one tab space)- $ cat file NARESH<b><b><b>KUMAR<t><t>PRADHAN... (3 Replies)
Discussion started by: NARESH1302
3 Replies

5. UNIX for Dummies Questions & Answers

how to append spaces(say 10 spaces) at the end of each line based on the length of th

Hi, I have a problem where I need to append few spaces(say 10 spaces) for each line in a file whose length is say(100 chars) and others leave as it is. I tried to find the length of each line and then if the length is say 100 chars then tried to write those lines into another file and use a sed... (17 Replies)
Discussion started by: prathima
17 Replies

6. UNIX for Advanced & Expert Users

Trimming the spaces

Hi, How can I remove the unwanted spaces in the line. 123456 789 ABC DEF. - I wanna remove the sapces in this line, I need the output 123456789ABCDEF. Pls help me...... (3 Replies)
Discussion started by: sharif
3 Replies

7. Shell Programming and Scripting

Why am I getting spaces when there is none??!!

param_data=`sqlplus -S $USER/$PASSWRD@$SCHEMA << EOF SET ECHO OFF NEWP 0 SPA 0 PAGES 0 FEED OFF HEAD OFF TRIMS ON VARIABLE param_data VARCHAR2(1000); WHENEVER SQLERROR EXIT SQL.SQLCODE ROLLBACK; SELECT INTERFACE_ID || '|' || PARAM_FILE || '|' || SESSION_NAME || '|' || PARAM_NAME ||... (2 Replies)
Discussion started by: Nomaad
2 Replies

8. UNIX for Dummies Questions & Answers

LS with spaces

Hi! I'm fairly new to UNIX so don't mention that my question is stupid. I have many problems with spaces in folders and files names. Let's say I have the following files: toto.txt this is toto.txt in /usr/local/this is a test/ Why the following commands works: ls "/usr/local/this... (2 Replies)
Discussion started by: darkyoda2
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
Login or Register to Ask a Question