Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: script to format line

36 views
Skip to first unread message

Kenny McCormack

unread,
May 25, 2012, 5:08:05 PM5/25/12
to
In article <jpordj$fdh$1...@dont-email.me>,
Jon LaBadie <jlab...@aXcXm.org> wrote:
>On 05/25/2012 03:52 PM, roger vaede wrote:
>> I have a file that doesn't have a field delimiter between the columns
>and I want to add a colon between each column. I can identify the
>columns by hard coding the range:
>> such as "col1 to col 10" "col11 to col24" etc...
>>
>> I am stuck.
>
>Look at gnu awk's FIELDWIDTHS variable. As an example:
>
> gawk '
> BEGIN { FIELDWIDTHS = "2 6 3 7 21" }
> { print $1 ":" $2 ":" $3 ":" $4 ":" $5 }
> ' datafile

Better:

BEGIN { FIELDWIDTHS = "2 6 3 7 21";OFS=":" }
$1=$1

Note1: Purist will object that there is a (subtle) bug in the above code. I
personally consider it a feature, but you are, of course, free to edit it as
you see fit.

Note2: (Obligatory net-copping) Please don't multi-post.

--
The motto of the GOP "base": You can't be a billionaire, but at least you
can vote like one.

Kenny McCormack

unread,
May 26, 2012, 11:09:17 AM5/26/12
to
In article <jppg71$va5$1...@dont-email.me>,
Ed Morton <morto...@gmail.com> wrote:
...
>> sed 's/^\(.\{10\}\)\(.\{14\}\).../\1:\2:.../'
>
>I'd probably fine gawks FIELDWIDTHS simpler but either way...

But will GAWK be willing to pay the fine?

Anyway, yes, agreed, and sed solutions are always ugly. That's why sed
people like them.

P.S. As noted earlier, the best way to do this is using FIELDWIDTHS and OFS.

--
But the Bush apologists hope that you won't remember all that. And they
also have a theory, which I've been hearing more and more - namely,
that President Obama, though not yet in office or even elected, caused the
2008 slump. You see, people were worried in advance about his future
policies, and that's what caused the economy to tank. Seriously.

(Paul Krugman - Addicted to Bush)

Kenny McCormack

unread,
May 26, 2012, 11:20:42 AM5/26/12
to
In article <barmar-069A1E....@news.eternal-september.org>,
Barry Margolin <bar...@alum.mit.edu> wrote:
...
>I'm on a Mac, it doesn't come with gawk, for some reason. Sed is more
>universal, although I wonder if all versions recognize \{n\} syntax.

The reason is because OSX is based on the BSD line of Unix, not the
Solaris/Linux/GNU line. So, you get what BSD'ers get.

Just out of cuiosity, are you looking to get GAWK for your Mac?

I ask because I had to go through a bit of pain to get it for myself, and
having done so, I'm willing to talk about it. I could send you a link to
the binary. Or, you could install Xcode - which does work, and allows you
to compile all the usual stuff - but Apple, in their majesty makes it a lot
harder to install than it should be. They make you install not only the
sink, but the entire kitchen, when all you want is a faucet and a drain...

--

Some of the more common characteristics of Asperger syndrome include:

* Inability to think in abstract ways (eg: puns, jokes, sarcasm, etc)
* Difficulties in empathising with others
* Problems with understanding another person's point of view
* Hampered conversational ability
* Problems with controlling feelings such as anger, depression
and anxiety
* Adherence to routines and schedules, and stress if expected routine
is disrupted
* Inability to manage appropriate social conduct
* Delayed understanding of sexual codes of conduct
* A narrow field of interests. For example a person with Asperger
syndrome may focus on learning all there is to know about
baseball statistics, politics or television shows.
* Anger and aggression when things do not happen as they want
* Sensitivity to criticism
* Eccentricity
* Behaviour varies from mildly unusual to quite aggressive
and difficult

rvae...@gmail.com

unread,
May 28, 2012, 9:30:20 PM5/28/12
to
thanks for the support, I am using REDHAT 5 as OS
0 new messages