Re: sed problem
From: Anthony Borla (ajborla_at_bigpond.com)
Date: 02/27/05
- Next message: shell: "Re: control Value of variable within multi-scripts"
- Previous message: wyl_lyf_at_yahoo.com: "Re: sed problem"
- In reply to: wyl_lyf_at_yahoo.com: "Re: sed problem"
- Next in thread: Ed Morton: "Re: sed problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 27 Feb 2005 05:00:47 GMT
<wyl_lyf@yahoo.com> wrote in message
news:1109469286.744634.132350@f14g2000cwb.googlegroups.com...
>
> Hello!
>
> Thanks for the reply.
>
> There is a blank in between group of entries. I could use
> awk or grep.
>
> Not sed in particular. Its just the first thing that came in
> my mind.;) But how do I use awk or grep for this?
>
> by run, i mean the next thing it picks up is the next group
> of text. :)
>
> > <snip>
> > > Input file:
> > > a=123
> > > b=456
> > > c=789
> > >
> > > a=abc
> > > b=def
> > > c=ghi
> > >
> > > I want to traverse through the file and get the input by
> > > group.
> >
I'm not exactly how you want your output to appear, but this should give you
an idea how 'awk' might be used for this task:
/* FILE: joinline.awk */
BEGIN {
FS = "=";
/* These may be overriden on command line */
if (KSEP == "") KSEP = ":";
if (DSEP == "") DSEP = "|";
}
/[^[:blank:]]/ { v[$1] = v[$1] $2 DSEP; }
END {
for (i in v) printf("%s %s %s\n", i, KSEP, v[i]);
}
Execute as follows [assume your data is in 'mydata.txt']:
awk -f joinline.awk mydata.txt
or, something like [change values of KSEP and DSEP as you require]:
awk -vKSEP=":" -vDSEP="|" -f joinline.awk mydata.txt
I hope this helps.
Anthony Borla
- Next message: shell: "Re: control Value of variable within multi-scripts"
- Previous message: wyl_lyf_at_yahoo.com: "Re: sed problem"
- In reply to: wyl_lyf_at_yahoo.com: "Re: sed problem"
- Next in thread: Ed Morton: "Re: sed problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|