Operating System - HP-UX
1823082 Members
3467 Online
109646 Solutions
New Discussion юеВ

Scripting question for you geniuses.

 
SOLVED
Go to solution
Sean OB_1
Honored Contributor

Scripting question for you geniuses.

Ok, I need to script the following.

Search standard out from a command and only display lines after a certain point.

EX:

netstat -a command

Look for "Active UNIX domain sockets"
and only display the lines of output that come after that appears.

11 REPLIES 11
Pete Randall
Outstanding Contributor
Solution

Re: Scripting question for you geniuses.

Sean,

From Handy One-Liners for Sed (attached):

# print section of file from regular expression to end of file
sed -n '/regexp/,$p'


Pete


Pete
curt larson_1
Honored Contributor

Re: Scripting question for you geniuses.

command |
awk '
/string/ {flag = 1;}
{if ( flag == 1 ) print $0;}'
H.Merijn Brand (procura
Honored Contributor

Re: Scripting question for you geniuses.

Or analogous from perl

# netstat -a command | perl -ne'/Active UNIX domain sockets/..undef and print'

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn

Re: Scripting question for you geniuses.

Sean,

Not at a machine right now, but doesn't 'netstat -af unix' pretty much give you the same thing?

HTH

Duncan

I am an HPE Employee
Accept or Kudo
Sean OB_1
Honored Contributor

Re: Scripting question for you geniuses.

Duncan,

It may, that wasn't really the command I wanted to do this on, but it was an easy command to show what I meant.
H.Merijn Brand (procura
Honored Contributor

Re: Scripting question for you geniuses.

No points for this, but what makes you prefer the longish awk statement over the perl one?
You don't like perl?
Just curious.

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Sean OB_1
Honored Contributor

Re: Scripting question for you geniuses.

No preference. I was able to test the top two and they worked as wanted.

Yours didn't work for me, although I'm sure it works.

Got this error: "Reading from a core file is no longer supported."
H.Merijn Brand (procura
Honored Contributor

Re: Scripting question for you geniuses.

At least it was not perl4, which gives a complete different error. Otherwise, I'm unable to reproducce that error with all the perl's I have installed here.
Better luck next time.

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Sean OB_1
Honored Contributor

Re: Scripting question for you geniuses.

root@datapro:/root-> which perl
/usr/bin/perl
root@datapro:/root-> perl -v

This is perl, v5.8.3 built for PA-RISC2.0
Biswajit Tripathy
Honored Contributor

Re: Scripting question for you geniuses.

And if you want something highly inefficient and
unnecessarily complicated than it should be, then
use:

# netstat -a | tail -n$(echo $(netstat -a | wc -l) - \
$(netstat -a | grep -n "YOUR_SEARCH_STRING" \
| head -n 1 | awk -F: '{print $1}') | bc)

No points for bad programming, please :-)

- Biswajit
:-)
H.Merijn Brand (procura
Honored Contributor

Re: Scripting question for you geniuses.

a5:/u/usr/merijn 103 > netstat -a | perl5.8.3 -ne '/425b7000/..undef and print'
4232ec00 dgram 0 0 425b7000 0 0 0 /dev/log.un
4297f200 dgram 0 0 4297a000 428fe180 0 0 /opt/dcelocal/var/rpc/local/01158/c-3/7000
42dcfc00 stream 0 0 0 67e2da00 0 0 /var/spool/sockets/ICE/4911
430afe00 stream 0 0 0 4d1a0d00 0 0
a5:/u/usr/merijn 104 > perl -v

This is perl, v5.8.5 built for PA-RISC2.0
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2004, Larry Wall


Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn