AWK experts - how would I code around this in awk...
Steve Flynn
anothermindbomb at gmail.com
Fri Feb 19 00:02:08 UTC 2010
On Thu, Feb 18, 2010 at 11:47 PM, Doug Robinson <dkrr at telus.net> wrote:
>>> Maybe a bash script that removes all CR's and LF's and uses echo to
>>> reinsert them every 20 characters would do the job.
>>>
>>> #######script
>>> OLDFILE="whatever"
>>> NEWFILE="whatever-new"
>>> touch $NEWFILE
>>> while read -n20 LINE
>>> do
>>> echo "$LINE" >>$NEWFILE
>>> done <$(cat $OLDFILE|tr -d "\n\r")
>>> exit 0
>>> ###########end script
>>>
>>> Alex
>>>
>>>
>>>
>> Geee - years & year since I thought in awk; but do you mean this?
>> BEGIN {
>> i = 1
>> }
>>
>> /.*/ {
>> if (i++ >= 3) {
>> printf ("%s\n", $1)
>> i =1;
>> }else {
>> printf ("%s ", $1)
>> }
>> }
>>
>> hundreds of thousands may talk a while just to read & write!
>
> or perhaps this:
>
> BEGIN {
> len = 0
> }
> END {
> print ""
> }
>
> /.*/ {
> if (len < 20) {
> printf ("%s", $1)
> len = len + length ($1)
> } else {
> printf ("%s\n", $1)
> len = 0
> }
> }
>
>
> anyway this is the idea - good luck with AWK - fun fun fun
I'll give all suggestions a crack through at work tomorrow. I did
consider reversing the file first and reading through it backwards on
the basis that it's easier to "append a record and move on" than
append a line to the previous line and delete the line you're about to
read. Just brainstorming at the moment and wondering if I'd picked the
right tool for the job. That's the trouble with *nux.
Have to work with AIX awk so there's no guarantee that perfect bash
works with 1971 implementation of ksh93 or even god-knows-what awk.
Been bitten by that before, sadly.
Sounds easy doesn't it - concatenate lines together until they are the
right length... how hard can it possibly be... /sigh
Steve
When one person suffers from a delusion it is insanity. When many
people suffer from a delusion it is called religion.
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
More information about the ubuntu-users
mailing list