stupid scripting question

From: Danielle Georgette <Danielle.Georgette_at_asx.com.au>
Date: Fri, 05 May 2000 17:16:10 +1000

I am humilated to ask a rather simple scripting question, especially since I
saw someone ask this question within the last few months and can't rememer
(or refind) the answer. This is driving me nuts and I cant see the forest
for the trees .

Simple problem: I have a file text.txt containing space formatted text:

a1 a2 a3
b1 b2 b3
c1 c2 c3

etc, where each column is 10 spaces wide.

I want to replace all the text in the middle column with the characters xx.

#!/bin/ksh
typeset -L10 colA
typeset -L10 colB="xx"
typeset -L10 colC
touch newtext.txt
for i in `cat text.txt`
do
colA=`echo $i |cut -c 1-10`
colC=`echo $i|cut -c 20-30`
echo $colA$colB$colC >> newtext.txt
done

But my script is breaking up each input line into the three parts, so what I
see in the output is:

a1
xx
a3
b1
xx
b3

I guess it has something to do with ksh interpreting spaces in the line as
field seperators, but how can I suppress/alter the script to stop this
happening ? I guess it could be done (probably better) in awk, and any
answers such will be welcome - but i'd also love an explaination as to why
the above happens as well.

Thanks!

Danielle

+-----------------------------------+---------------------------------+
| Danielle Georgette | Unix is very user friendly, its |
| Unix Admin | just rather particular about |
| danielle.georgette_at_asx.com.au | who it makes friends with. |
+-----------------------------------+---------------------------------+
| All opinions are my own unless clearly stated otherwise. |
+---------------------------------------------------------------------+
 
Received on Fri May 05 2000 - 07:17:12 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:40 NZDT