- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Regarding shell script
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2006 11:52 PM
09-20-2006 11:52 PM
I want to extract only the toos_details records which has owner as localexchange and outage as CAD and write it into a new file. How do i do it? Do i need to write a C program or i can achieve through shell script
toos_details
rpt_clli ARTNVACK04T
tfn 22
trfus IT
trfcl PH
ofcls 34
ttm CPR
cllia ARTNVACK04T
dpl 77
clliz SGINTXAA02T
outage CAD
ins Y
oos_ts Sep 22 11:24:10 2003
topas_ts Sep 21 03:50:28 2006
tgak 51303
btfn 0001
num_trk 72
num_toos 72
gap 022
owner localexchange
toos_details
rpt_clli ARTNVACK04T
tfn 8001
trfus AD
trfcl DF
ofcls 35
ttm ACDCG0
cllia ARTNVACK04T
dpl ZZ
clliz TYCRVAAMN01
outage MTC
ins Y
oos_ts Jan 14 15:01:06 2006
topas_ts Sep 21 03:50:28 2006
tgak 8985
btfn 8001
num_trk 1
num_toos 1
gap 070
owner nodal
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2006 12:09 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2006 12:38 AM
09-21-2006 12:38 AM
Re: Regarding shell script
This is better, since it retains the first section header --- the "toos_details":
# cat ./extract
#!/usr/bin/perl
local $/ = undef;
@sections = split( /(?=(toos_details))/, <> );
for $_ (@sections) {
print if /owner\s+localexchange/ and /outage\s+CAD/;
}
...run as:
# ./extract file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2006 12:45 AM
09-21-2006 12:45 AM
Re: Regarding shell script
>cat extract
#!/usr/contrib/bin/perl
local $/ = undef;
sections = split /toos_details/, <>;
sections) {
print if /owner\s+localexchange/ and /outage\s+CAD/;
}
>extract O380391mi
syntax error in file ./extract at line 2, next 2 tokens "local $/ "
syntax error in file ./extract at line 3, next 2 tokens "/,"
Execution of ./extract aborted due to compilation errors.
2. If i redirect the output of the script
do i need to do the below way
extract O380391mi 1>report.out
or
any script needs to be modified?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2006 01:00 AM
09-21-2006 01:00 AM
Re: Regarding shell script
It appears that you are using a very old versino of Perl. Try this:
#!/usr/contrib/bin/perl
$/ = undef;
@sections = split( /toos_details/, <> );
for $_ (@sections) {
print if /owner\s+localexchange/ && /outage\s+CAD/;
}
Also, do:
# /usr/contrib/bin/perl -v
...If the version isn't 5.x then by all means fetch and install a current version:
http://h20293.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=PERL
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2006 02:24 AM
09-21-2006 02:24 AM
Re: Regarding shell script
Although I very much prefer Perl, here's an awk solution that fits your data:
# awk 'BEGIN{RS=""};/localexchange/ && /CAD/ {print $0;print ""}' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2006 06:21 AM
09-21-2006 06:21 AM
Re: Regarding shell script
>cat extract1
#!/usr/contrib/bin/perl
$/ = undef;
sections = split( /toos_details/, <> );
sections) {
print if /owner\s+localexchange/ && /outage\s+CAD/;
}
> extract1 O380391mi
Illegal item (LITERAL) as lvalue in file ./extract1 at line 3, next 2 tokens ");"
syntax error in file ./extract1 at line 4, next 2 tokens "sections)"
Execution of ./extract1 aborted due to compilation errors.
2.
> /usr/contrib/bin/perl -v
This is perl, version 4.0
$RCSfile: perl.c,v $$Revision: 4.0.1.8 $$Date: 1993/02/05 19:39:30 $
Patch level: 36
Copyright (c) 1989, 1990, 1991, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 4.0 source kit.
3. I will try with awk.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-21-2006 06:32 AM
09-21-2006 06:32 AM
Re: Regarding shell script
In your last post (above):
1. You mis-pasted what I posted.
2. I suspected that you had a Perl 4. That's ancient! Upgrade to something more useful, as I suggested.
3. In the meantime, the 'awk' solution should help.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2006 01:51 AM
09-22-2006 01:51 AM
Re: Regarding shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-22-2006 01:56 AM
09-22-2006 01:56 AM
Re: Regarding shell script
Per you last request:
# awk 'BEGIN{N=0;RS=""};/^toos_details/ {N++};/localexchange/ && /CAD/ {print $0;print ""};END{print N}' file
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2006 07:22 AM
09-23-2006 07:22 AM
Re: Regarding shell script
~cheers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-23-2006 10:07 PM
09-23-2006 10:07 PM
Re: Regarding shell script
The only change i made to james awk script is
awk 'BEGIN{N=0;RS=""};/localexchange/ && /CAD/ {print $0;print "";N++};END{print N}' file
Also how do i change this one if i want to print all the toos_details other than toos_details which have entries localexchange and cad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2006 04:20 AM
09-24-2006 04:20 AM
Re: Regarding shell script
# awk 'BEGIN{RS=""}/toos_details/' inputfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2006 07:39 PM
09-24-2006 07:39 PM
Re: Regarding shell script
Basically i want the toos_details records which doesn't have local exchange and CAD to be printed and not all the toos_details.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2006 11:58 PM
09-24-2006 11:58 PM
Re: Regarding shell script
You wrote, "Basically i want the toos_details records which doesn't have local exchange and CAD to be printed and not all the toos_details".
For this, I suggest:
# awk 'BEGIN{N=0;RS=""};!(/localexchange/ && /CAD/) {print $0;print "";N++};END{print N}' file
...The "!" negates the match expression.
If you are interested in more 'awk' details, I suggest an examination of:
http://www.gnu.org/software/gawk/manual/
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2006 07:45 PM
09-26-2006 07:45 PM
Re: Regarding shell script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-26-2006 07:54 PM
09-26-2006 07:54 PM