Code Comments
Programming Forum and web based access to our favorite programming groups.I have thousands of lines as: TITLE = "Agent.Daily.AccessDenials", UNITS = "Runs",HISTORY_TIME = "600", HISTORY_SPAN = 0, HISTORY_LEVEL = False, Where I need to delete all the info that follows the "UNITS" match. I wonder if there is a way to do this using sed or awk. Any help would be very helpful. Regards. Raul.
Post Follow-up to this messageRaul B <rnrodrig@todito.com> wrote:
> I have thousands of lines as:
>
> TITLE = "Agent.Daily.AccessDenials", UNITS = "Runs",HISTORY_TIME =
> "600", HISTORY_SPAN = 0, HISTORY_LEVEL = False,
>
> Where I need to delete all the info that follows the "UNITS" match.
>
> I wonder if there is a way to do this using sed or awk.
Do you mean:
awk '/UNITS/{
match("^.*UNITS = \"[^\"]*\",$0)
print substr($0,1,RLENGTH)
}
Post Follow-up to this messageRaul B wrote: > I have thousands of lines as: > > TITLE = "Agent.Daily.AccessDenials", UNITS = "Runs",HISTORY_TIME = > "600", HISTORY_SPAN = 0, HISTORY_LEVEL = False, > > Where I need to delete all the info that follows the "UNITS" match. > > I wonder if there is a way to do this using sed or awk. It's easiest in sed: sed 's/, UNITS =.*$//' Ed.
Post Follow-up to this messageIn article <a7cbebc9.0407290905.2b81d3b4@posting.google.com>, Raul B <rnrodrig@todito.com> wrote: >I have thousands of lines as: > >TITLE = "Agent.Daily.AccessDenials", UNITS = "Runs",HISTORY_TIME = >"600", HISTORY_SPAN = 0, HISTORY_LEVEL = False, > >Where I need to delete all the info that follows the "UNITS" match. > >I wonder if there is a way to do this using sed or awk. > >Any help would be very helpful. How about using the commas and deleting everything from the second comma on: sed 's/\([^,]*,[^,]*\).*/\1/' infile Chuck Demas -- Eat Healthy | _ _ | Nothing would be done at all, Stay Fit | @ @ | If a man waited to do it so well, Die Anyway | v | That no one could find fault with it. demas@theworld.com | \___/ | http://world.std.com/~cpd
Post Follow-up to this messageIn article <cebjm8$6pc@netnews.proxy.lucent.com>, Ed Morton <morton@lsupcaemnt.com> wrote: > > >Raul B wrote: > > >It's easiest in sed: > >sed 's/, UNITS =.*$//' > > Ed. But, of course, completely off topic for this newsgroup. Win some, lose some.
Post Follow-up to this messageThanks a lot four help, the solutions that says: sed 's/, UNIT = .*$//' was the simplest and the easiest. Again thanks for your help.
Post Follow-up to this messageIn article <a7cbebc9.0407301339.2d13ec37@posting.google.com>, Raul B <rnrodrig@todito.com> wrote: >Thanks a lot four help, the solutions that says: > >sed 's/, UNIT = .*$//' > >was the simplest and the easiest. sed 's/,.*//' is simpler given what you seem to want. Chuck Demas -- Eat Healthy | _ _ | Nothing would be done at all, Stay Fit | @ @ | If a man waited to do it so well, Die Anyway | v | That no one could find fault with it. demas@theworld.com | \___/ | http://world.std.com/~cpd
Post Follow-up to this message
Charles Demas wrote:
> In article <a7cbebc9.0407301339.2d13ec37@posting.google.com>,
> Raul B <rnrodrig@todito.com> wrote:
>
>
>
> sed 's/,.*//'
>
> is simpler given what you seem to want.
>
>
> Chuck Demas
>
Good point, maybe I could even redeem myself from earlier with a topical
response ;-):
awk -F, '{print $1}'
but I just can't resist a final OT one too:
cut -d, -f1
For the OP - questions about sed (or cut or any other non-awk tool) are
better directed to comp.unix.shell.
Sorry,
Ed.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.