Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Question about sed
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.

Report this thread to moderator Post Follow-up to this message
Old Post
Raul B
07-29-04 08:55 PM


Re: Question about sed
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.


Do you mean:
awk '/UNITS/{
match("^.*UNITS = \"[^\"]*\",$0)
print substr($0,1,RLENGTH)
}


Report this thread to moderator Post Follow-up to this message
Old Post
Ian Stirling
07-29-04 08:55 PM


Re: Question about sed

Raul 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.



Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
07-29-04 08:55 PM


Re: Question about sed
In 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

Report this thread to moderator Post Follow-up to this message
Old Post
Charles Demas
07-29-04 08:55 PM


Re: Question about sed
In 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.


Report this thread to moderator Post Follow-up to this message
Old Post
Kenny McCormack
07-30-04 01:55 AM


Re: Question about sed
Thanks a lot four help, the solutions that says:

sed 's/, UNIT = .*$//'

was the simplest and the easiest.

Again thanks for your help.

Report this thread to moderator Post Follow-up to this message
Old Post
Raul B
07-31-04 01:55 AM


Re: Question about sed
In 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

Report this thread to moderator Post Follow-up to this message
Old Post
Charles Demas
07-31-04 01:55 AM


Re: Question about sed

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.


Report this thread to moderator Post Follow-up to this message
Old Post
Ed Morton
07-31-04 08:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

AWK archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:25 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.