data:
1234567890abcdefghij1234567890...
code:
cut -b1-10 data >> data1
cut -b11-20 data >> data1
cut -b21-30 data >> data1
my result:
1234567890
abcdefghij
1234567890
.........
How my codes should be if I would use "while syntax" coding?
data:
1234567890abcdefghij1234567890...
code:
cut -b1-10 data >> data1
cut -b11-20 data >> data1
cut -b21-30 data >> data1
my result:
1234567890
abcdefghij
1234567890
.........
How my codes should be if I would use "while syntax" coding?
instead of while , u can use the awk which is very flexible enough to handle the task, since while suffers in searching a text
awk ' { print substr($0,1,10) "\n" substr($0,11,10) "\n" substr($0,21,10) >> "data1" } ' data
sed 's/\(.\{10\}\)\(.\{10\}\)\(.*\)/\1\
\2\
\3/' filename
To loop through a string, 10 characters at a time:
$ cat looper
#! /usr/bin/ksh
string=aaaaaaaaaabbbbbbbbbccccccccccddddddddddeeeeeeeeeefffffffffffgggggggggg
typeset -L10 tenchr
while ((${#string})); do
if ((${#string} > 10)); then
tenchr=$string
piece=$tenchr
string=${string#$piece}
else
piece=$string
string=""
fi
echo $piece $string
done
exit 0
$ ./looper
aaaaaaaaaa bbbbbbbbbccccccccccddddddddddeeeeeeeeeefffffffffffgggggggggg
bbbbbbbbbc cccccccccddddddddddeeeeeeeeeefffffffffffgggggggggg
cccccccccd dddddddddeeeeeeeeeefffffffffffgggggggggg
ddddddddde eeeeeeeeefffffffffffgggggggggg
eeeeeeeeef ffffffffffgggggggggg
ffffffffff gggggggggg
gggggggggg
$