Re: sed problem

From: Anthony Borla (ajborla_at_bigpond.com)
Date: 02/27/05


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



Relevant Pages

  • Re: General UNIX puzzle
    ... All of those (sed, awk, grep) involve making a copy of the original file ... The gnu shtool is one of the most useful tools for this for in-place ... A Galileo could no more be elected president of the United States than ...
    (freebsd-questions)
  • Re: ssh and chroot
    ... ++ echo /bin/mkdir ... ++ awk '' ... ++ grep '^/' ...
    (comp.security.ssh)
  • Re: The smartest band in the world?
    ... I mainly use grep, but I'm ... going to learn awk and sed and improve my bash scripting. ... Oracle accreditation coure, well in the grad courses at least, everything ...
    (alt.guitar)
  • Re: Difference between Cygwin and DOS handling of string input
    ... Ton of userland tools that make work possible (perl, sed, awk, grep, ... cmd.exe is a shell in that it's a TTY that lets you run commands, ...
    (comp.lang.c)
  • Re: grep switches
    ... grep -n 'pattern' file /dev/null ... grep, so all I need is to the file names and line numbers of the text ... awk '/pattern/ ... But there are some unwanted error ...
    (comp.unix.shell)