- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script Help on Line Selection
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
08-05-2005 08:54 AM
08-05-2005 08:54 AM
==================================
SQL> select tablespace_name,sum(bytes) free from dba_free_space group by tablesp
ace_name;
TABLESPACE_NAME FREE
------------------------------ ----------
DRSYS 16637952
INDX 20963328
PRODDATA 2791825408
PRODINDEX 592568320
RBS 633856000
SYSTEM 318390272
TEMP 1048567808
TOOLS 5234688
USERS 65265664
9 rows selected.
==========================================
if I cat the spool file, I have all lines. How to only get the lines without head and tail, or only for tablespace_name listings like:
TABLESPACE_NAME FREE
------------------------------ ----------
DRSYS 16637952
INDX 20963328
PRODDATA 2791825408
PRODINDEX 592568320
RBS 633856000
SYSTEM 318390272
TEMP 1048567808
TOOLS 5234688
USERS 65265664
Any help is appreciated.
Steven
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2005 10:09 AM
08-05-2005 10:09 AM
Solutionassuming first line you want is the
TABLESPACE_NAME FREE
and you do not want including line
9 rows selected
and anything after that
# you placed the sql output is in outfile
(( startline=`grep -n TABLESPACE_NAME outfile | cut -d: -f1` - 1 ))
sed -e "1,${startline}d" outfile >interimfile
endline=`grep -n "rows selected" outfile | cut -d: -f1`
sed -e "${endline},\$d" outfile | sed -e "1,${startline}d" > final_output
you can use command substitutions and combine all these 3 lines into one, gigantic, ugly sed command but I preferred to put it down this way, so what I was telling was obvious.
Hope this helps
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-05-2005 10:11 AM
08-05-2005 10:11 AM
Re: Script Help on Line Selection
(( startline=`grep -n TABLESPACE_NAME outfile | cut -d: -f1` - 1 ))
endline=`grep -n "rows selected" outfile | cut -d: -f1`
sed -e "${endline},\$d" outfile | sed -e "1,${startline}d" > final_output
UNIX because I majored in cryptology...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2005 07:22 PM
08-07-2005 07:22 PM
Re: Script Help on Line Selection
i would suggest not to filter the output but to configure everything so that only the desired lines are in the output. Thats much easier to maintain.
If you use some Oracle set commands you can configure your output pretty easy.
For example this will give you a report without the command itselve, and without the sql feedback (xx rows selected).
set NEWPAGE 0;
set PAGESIZE 0;
set LINESIZE 560;
set COLSEP '';
set FEEDBACK OFF;
set HEADING OFF;
SET ECHO OFF;
set VERIFY OFF;
set TERMOUT OFF;
spool
SELECT
spool off;
quit;
Put this in a script and give it a try. You might want to set HEADING to ON. But the rest should be pretty close to what you need.
Hope this helps
Regards Stefan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2005 08:33 PM
08-07-2005 08:33 PM
Re: Script Help on Line Selection
#!/bin/ksh
SPOOL=test.log
line=$(wc -l $SPOOL)
let end=$line-2
start=$(grep -n ";" ${SPOOL} | cut -d":" -f1)
sed -e "$start,$end !d" $SPOOL
hth.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2005 09:58 PM
08-07-2005 09:58 PM
Re: Script Help on Line Selection
But if you have several files with then already then you could use the following 'cleanup' perl one-liner
perl -e 'while (<>) { $x++ if /^---/; $x-- if /rows select/;print $line if
$x; $line=$_} < old.txt > new.txt
This remembers a prior line in $line.
It looks at the current like whether to start or stop printing that prior line.
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2005 05:22 AM
08-08-2005 05:22 AM
Re: Script Help on Line Selection
=============================================
# sqlplus -s
spool filename.out
select tablespace_name,sum(bytes) free from dba_free_space group by tablespace_name
/
spool off
exit
EOF
=============================================
cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2005 09:48 AM
08-08-2005 09:48 AM
Re: Script Help on Line Selection
Put your select statement in the buffer (and leave it there) BEFORE doing your spool command. Then, put in the spool command, then just do a "/" to run the select. Put a "spool off" immediately after the select runs. This gives a pretty clean output, suitable for sending to lpt once you've played with the newpage, pagesize, etc.
Also call sqlplus in SILENT mode (-S).
set NEWPAGE 0
set PAGESIZE 0
set LINESIZE 560
set COLSEP ''
set FEEDBACK OFF
set HEADING OFF
SET ECHO OFF
set VERIFY OFF
set TERMOUT OFF
SELECT
spool
/
spool off
quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2005 07:19 PM
08-08-2005 07:19 PM
Re: Script Help on Line Selection
lists.lst : This will have the tablespace details.
cat lists.lst | grep -v "rows selected" | grep -v "TABLESPACE_NAME" | grep -v "-"
After executing the above commnad you will get only the table space names.
-- Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2005 03:22 AM
08-09-2005 03:22 AM
Re: Script Help on Line Selection
By far, I find 2 solutions that are simply and workable:
1) sql coding....
spool xxx
/
so that it does not show the sqlcode.
2) sed -n 3,10p /tmp/xxx.lst
Again, this is a great forum from where you brain stormed and try all ways for a fix.