11-02-2006
grep + lines after
Hello again, I'm still working on the redo of my script I created before and came across a grep question.
I'm on SunOS 5.9 and using the Korn Shell. I'm writing a function to check for validation of root disks being mirrored. If the server allows me to use metastat, I'm looking to show it has root disks, it has mirrors, and that the status is "okay". As always when I post, I give a little to take a little.
My Offering, the first 2/3rds of my Metastat Mirror Check Function:
#!/bin/ksh
#set -x
mirnumvar=`metastat | grep "^d" | grep "Mirror" | cut -d: -f1`
for varmirnum in $mirnumvar
do
#echo $varmirnum
mirvar=`metastat | grep "^d" | grep "Mirror" | grep $varmirnum | cut -d: -f1 | cut -dd -f2`
#echo $mirvar
submirvar=`metastat | grep "^d" | grep "d.$mirvar" | cut -d: -f1`
#echo $submirvar
echo "Mirror $varmirnum Contains Submirrors:" $submirvar
done
This gives output of:
Mirror d4 Contains Submirrors: d14 d24
Mirror d3 Contains Submirrors: d13 d23
Mirror d1 Contains Submirrors: d11 d21
Mirror d0 Contains Submirrors: d10 d20
Mirror d5 Contains Submirrors: d15 d25
I'm now working on grouping together statuses with their respective submirrors. One of the commands I've tinkered with that has gotten me close to the results is the following:
metastat | egrep 'Submirror of|State:'
Results:
State: Okay
State: Okay
d14: Submirror of d4
State: Okay
d24: Submirror of d4
State: Okay
State: Okay
State: Okay
d13: Submirror of d3
State: Okay
d23: Submirror of d3
State: Okay
State: Okay
State: Okay
d11: Submirror of d1
State: Okay
d21: Submirror of d1
State: Okay
State: Okay
State: Okay
d10: Submirror of d0
State: Okay
d20: Submirror of d0
State: Okay
State: Okay
State: Okay
d15: Submirror of d5
State: Okay
d25: Submirror of d5
State: Okay
I have bolded what my desired results would contain, the submirrors and it's statuses underneath it. The other State: Okay's are from the Main root disk Mirrors. Would I be working with properties of grep to try and grep the line after the submirror or a different command to tackle this scenario. As always, hats off and many thanks to those that can tackle this conundrum.
~Ryan
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
suppose i have a file structure(serial file)--
----------
----------
---------
summery
--------
------
--------
finished
-----
-------
i want to fetch lines from summery to finished
i can get line of summery by grep command. but how can i fetch lines untill it reaches finished.probably... (2 Replies)
Discussion started by: arghya_owen
2 Replies
2. Shell Programming and Scripting
Hi
I am writing a script which should read a file and search for certain strings 'approved' or 'removed' and retain only those lines that contain the above strings.
Ex: file name 'test'
test:
approved package
waiting for approval package
disapproved package
removed package
approved... (14 Replies)
Discussion started by: vj8436
14 Replies
3. Shell Programming and Scripting
Hi folks
I am not allowed to install GNU grep on AIX.
Here my code excerpt:
grep_fatal () {
/usr/sfw/bin/gegrep -B4 -A2 "FATAL|QUEUE|SIGHUP"
}
Howto the same on AIX based machine?
from manual GNU grep
‘--after-context=num’
Print num lines of trailing context after... (4 Replies)
Discussion started by: slashdotweenie
4 Replies
4. Shell Programming and Scripting
I have several very large file that are extracts from Oracle tables. These files are formatted in XML type syntax with multiple entries like:
<ROW>
some information
more information
</ROW>
I want to grep for some words, then print all lines between <ROW> AND </ROW>. Can this be done with AWK?... (7 Replies)
Discussion started by: jbruce
7 Replies
5. Shell Programming and Scripting
Hi,
my xml files looks something like this
<Instance Name="New York">
<Description></Description>
<Instance Name="A">
<Description></Description>
<PropertyValue Key="false" Name="Building A" />
</Instance>
<Instance Name="B">
... (4 Replies)
Discussion started by: tententen
4 Replies
6. Shell Programming and Scripting
Hi,
I have one file, say file 1, that has data like below where 19900107 is the date,
19900107 12 144 129 0.7380047
19900108 12 168 129 0.3149017
19900109 12 192 129 3.2766666E-02
... (3 Replies)
Discussion started by: Wynner
3 Replies
7. Shell Programming and Scripting
I have an input file
12.4 1.72849432773174e+01 -7.74784188610632e+01
12.5 9.59432114416327e-01 -7.87018212757537e+01
15.6 5.20139995965960e-01 -5.61612429666624e+01
29.3 3.76696387248366e+00 -7.42896194101892e+01
32.1 1.86899877018077e+01 -7.56508762501408e+01
35 6.98857157014640e+00... (2 Replies)
Discussion started by: chrisjorg
2 Replies
8. Shell Programming and Scripting
Hello,
I want to extract from a file like :
20120530025502914 | REQUEST | whatever
20120530025502968 | RESPONSE | whatever
20120530025502985 | RESPONSE | whatever
20120530025502996 | REQUEST | whatever
20120530025503013 | REQUEST | whatever
20120530025503045 | RESPONSE | whatever
I want... (14 Replies)
Discussion started by: black_fender
14 Replies
9. UNIX for Advanced & Expert Users
I'm trying to grep for lines not containing a #. I'm not getting the syntax right. This is what I have tried so far.
grep -v \\# /home/bob/.config/vlc/vlcrc
grep -v '\\#' /home/bob/.config/vlc/vlcrc
grep -v "\\\\#" /home/bob/.config/vlc/vlcrcI tried to look at this thread of mine for ideas... (12 Replies)
Discussion started by: cokedude
12 Replies
10. Shell Programming and Scripting
say we have :
2914 | REQUEST | whatever
2914 | RESPONSE | whatever
2914 | SUCCESS | whatever
2985 | RESPONSE | whatever
2986 | REQUEST | whatever
2990 | REQUEST | whatever
2985 | RESPONSE | whatever
2996 | REQUEST | whatever
2010 | SUCCESS | whatever
2013 | REQUEST | whatever
2013 |... (7 Replies)
Discussion started by: Saumitra Pandey
7 Replies
LEARN ABOUT SUSE
app::prove::state::result
App::Prove::State::Result(3pm) Perl Programmers Reference Guide App::Prove::State::Result(3pm)
NAME
App::Prove::State::Result - Individual test suite results.
VERSION
Version 3.17
DESCRIPTION
The "prove" command supports a "--state" option that instructs it to store persistent state across runs. This module encapsulates the
results for a single test suite run.
SYNOPSIS
# Re-run failed tests
$ prove --state=fail,save -rbv
METHODS
Class Methods
"new"
my $result = App::Prove::State::Result->new({
generation => $generation,
tests => \%tests,
});
Returns a new "App::Prove::State::Result" instance.
"state_version"
Returns the current version of state storage.
"test_class"
Returns the name of the class used for tracking individual tests. This class should either subclass from "App::Prove::State::Result::Test"
or provide an identical interface.
"generation"
Getter/setter for the "generation" of the test suite run. The first generation is 1 (one) and subsequent generations are 2, 3, etc.
"last_run_time"
Getter/setter for the time of the test suite run.
"tests"
Returns the tests for a given generation. This is a hashref or a hash, depending on context called. The keys to the hash are the individual
test names and the value is a hashref with various interesting values. Each k/v pair might resemble something like this:
't/foo.t' => {
elapsed => '0.0428488254547119',
gen => '7',
last_pass_time => '1219328376.07815',
last_result => '0',
last_run_time => '1219328376.07815',
last_todo => '0',
mtime => '1191708862',
seq => '192',
total_passes => '6',
}
"test"
my $test = $result->test('t/customer/create.t');
Returns an individual "App::Prove::State::Result::Test" instance for the given test name (usually the filename). Will return a new
"App::Prove::State::Result::Test" instance if the name is not found.
"test_names"
Returns an list of test names, sorted by run order.
"remove"
$result->remove($test_name); # remove the test
my $test = $result->test($test_name); # fatal error
Removes a given test from results. This is a no-op if the test name is not found.
"num_tests"
Returns the number of tests for a given test suite result.
"raw"
Returns a hashref of raw results, suitable for serialization by YAML.
perl v5.12.1 2010-04-26 App::Prove::State::Result(3pm)