I don't want to truncate spaces


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting I don't want to truncate spaces
# 1  
Old 09-08-2008
I don't want to truncate spaces

I have a script that is adding text to a existing file and creating new file.
This part is working fine....
But the new file is truncated by script and all null spaced column are truncated.
What is my solution...please some body advice ....
thanks in advance

pre_line="+_)(*&"
spaces=" "
while read line
do
a=`echo "$line" | awk '{ print index($0,"CTCTL") }'`
if [ "$a" != 0 ] ;
then
if
[ "$pre_line" == "+_)(*&" ] ;
then
echo "$line" >> $2
pre_line
=$line
else
echo "ENDENDEND" >> $2
echo
"$line" >> $2
fi
else
echo "$line" >> $2
fi
done
< $1
echo
"ENDENDEND" >> $2
# 2  
Old 09-08-2008
by default read gets rid leading and trailing spaces. try changing IFS and consider using code tags when you post code....

Code:
pre_line="+_)(*&"
spaces=" "
while IFS='\n'; read line
do
       IFS=" "
	a=`echo "$line" | awk '{ print index($0,"CTCTL") }'`
	if [ "$a" != 0 ] ;
	then
		if [ "$pre_line" == "+_)(*&" ] ;
		then
			echo "$line" >> $2
			pre_line=$line
		else 
			echo "ENDENDEND" >> $2
			echo "$line" >> $2
		fi
	else
	echo "$line" >> $2
	fi
done < $1
IFS=" "
echo "ENDENDEND" >> $2

# 3  
Old 09-08-2008
It worked fine

Thanks for the quick response...
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

I don't want to truncate trailing spaces and ^M at the end of line

I have a script wherein I access each line of the file using a FOR loop and then perform some operations in each line. The problem is each line that gets extracted in FOR loop truncates trailing blank spaces and control characters (^M) that is present at the end of each line. I don't wan this to... (5 Replies)
Discussion started by: Shobana_s
5 Replies

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

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

4. Shell Programming and Scripting

awk script to remove spaces - examples don't show up correctly

I have the following data from a manual database dump. I need to format the columns so that I can import them into an excel spread sheet. So far I have been able to get past the hurdles with vi and grep. Now I have one last issue that I can't get past. Here is an example of the data. Here is... (18 Replies)
Discussion started by: Chris_Rivera
18 Replies

5. UNIX for Advanced & Expert Users

*** Truncate certain field ***

I have a file in which I need to truncate 15th field to have only one character like Put --> P and if i have no value in 15th field, it should be "O" (Other) would really appreciate the reponses, thnx in advance:b: (2 Replies)
Discussion started by: sannmayaz
2 Replies

6. Shell Programming and Scripting

How to truncate as filesize?

Hello everybody it's me again. I have a procces that is writing in a 'file1' automatically but i want to truncate 'file1' to a filesize 'x' that mean if the 'file1' size is 'x' i want to delete the first lines while the last lines are being writed, that have sence? in the process are an... (1 Reply)
Discussion started by: Lestat
1 Replies

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

8. UNIX for Dummies Questions & Answers

Truncate what is It?

what does this command do ? as in does this command just make sure everything in the file is executed? or does it flush the file? Actually this is used on a file in a progress database but I believe it is a unix command? (2 Replies)
Discussion started by: rocker40
2 Replies
Login or Register to Ask a Question