1846842 Members
8323 Online
110256 Solutions
New Discussion

Re: Script Help

 
SOLVED
Go to solution
Junior C.
Frequent Advisor

Script Help

All,

I want to delete line _____ from the following output.

ACTUATE_NETDATA
INTDATA1_INTDAT
___________
hncprod_group4
intdata1_full_h

result i'm looking for.
ACTUATE_NETDATA
INTDATA1_INTDAT
hncprod_group4
intdata1_full_h


13 REPLIES 13
John Poff
Honored Contributor

Re: Script Help

Hi,

One way to do it is to use 'grep':

grep -v '_____' inputfile



JP
John Poff
Honored Contributor
Solution

Re: Script Help

Or if you are a fan of 'sed':

sed '/_____/d' inputfile


JP
John Poff
Honored Contributor

Re: Script Help

And then there is always Perl:

perl -ne 'print unless /_____/;' inputfile



JP
Junior C.
Frequent Advisor

Re: Script Help

John,

sed '/_____/d' inputfile

Work

Thanks,
James R. Ferguson
Acclaimed Contributor

Re: Script Help

Hi:

I'd use 'sed', but tighten the matching:

# sed -e '/^_*$/d' filename

Hence lines consisting *only* of underscore characters...

Regards!

...JRF...
H.Merijn Brand (procura
Honored Contributor

Re: Script Help

James, that'll also delete the *empty* lines, which was not the question

# perl -ne'/^_+$/ or print'
Enjoy, Have FUN! H.Merijn
John Poff
Honored Contributor

Re: Script Help

It's interesting that out of the three ways I posted to do it, the author chose the 'sed' method which would have been my last choice.

Someday I've got to sit down and really learn Perl regular expressions. It just won't stick in my mind, kind of like all that English grammar I couldn't get to stick in my mind back in school. It seems to me that regular expressions ranks right up there with gerunds and past participles. Ouch! :)

JP
James R. Ferguson
Acclaimed Contributor

Re: Script Help

Hi Merijn!

Yes, you are correct. I did not mean to delete *empty* lines and *should* have written:

# sed -e '/^__*$/d' filename

...THAT IS, *two* underscore characters preceeding the asterisk so that the match is *one* underscore anchored at the line's start, followed by *zero or more* underscore's anchored to a newline.

The extended regular expression:

^_+$

understood by 'perl', works nicely too with 'egrep' ['grep -E'] or with 'awk' but not with 'sed'.

Regards!

...JRF...
H.Merijn Brand (procura
Honored Contributor

Re: Script Help

James, I know :] GNU sed however /does/ recognize the + metacharacter. One more reason to learn perl? One more reason to replace all default commands with there superior GNU equivalent (tar springs to mind)

FWIW The regex bible from Jeffrey Friedl (http://www.oreilly.com/catalog/regex/) has nice comparison tables for the most common filter programs in what regex flavour they accept.
Enjoy, Have FUN! H.Merijn
James R. Ferguson
Acclaimed Contributor

Re: Script Help

Hi (again) Merijn:

Your points are well taken. Ah, yes, to GNU or not to GNU...a good subject for discussion onto itself.

Thanks for the link. As you are probably aware, the book has a 2nd edition which certainly appears to be worth the read:

http://www.oreillynet.com/pub/a/network/2002/07/15/regexp.html

With warmest regards!

...JRF...
H.Merijn Brand (procura
Honored Contributor

Re: Script Help

I know, and I'm proud to be among the first few to find the errors in the book. Please note the errata area on the web when reading the book. Some are very misleading, and the stuff dealt with is complicated enough as it is already.
Enjoy, Have FUN! H.Merijn
harry d brown jr
Honored Contributor

Re: Script Help

Junior,

You should take care of this:

This member has assigned points to 13 of 86 responses to his/her questions.

You can find your previous posts in your profile:

http://forums.itrc.hp.com/cm/TopSolutions/1,,CA485690!1!questions,00.html

live free or die
harry
Live Free or Die
John Meissner
Esteemed Contributor

Re: Script Help

good call Harry - People shouldn't be able to ask questions until they at least assign 0 points to a post... let alone awarding posts that are helpful
All paths lead to destiny