Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
AXIONAL_INDEX 62.2645833
DATA 71.926875
SYSAUX .885200923
SYSTEM 1.04007771
TEMP 0
UNDOTBS1 .008392338
USERS 0
7 rows selected.
My 'problem' is that I don't know up front how many tablespaces there are so I'd have to check all databases and 'hardcode' the tablespaces in my script. Is there any way to 'automate' this knowing that 'rows selected' preceded by a number is always the last line and using a sort of counter to auto-adjust the number to put in the -e 's/ /\n/2' part?
Also if you know of a 'cleaner' solution (I'm sure some of you can come up with a nifty one-liner) I'd appreciate the help.
cut -c74- infile | sed 's/\([A-Z][_A-Z0-9]* [0-9\.][0-9\.]*\) /\1\n/g'
I assumed that the first 74 characters are the header and always the same length (the cut command).
The sed command uses back-referencing (that what is found in the search part, all between \( and \), is used as the replace part, the \1 part).
The sed command looks for tablenames that contain these possible characters: Starts with A-Z, followed by A-Z, 0-9 or a _ (zero or more times)
This must be followed by a space and 0-9 or a dot followed by 0-9 and/or a dot (zero or more times). followed by a space.
What is found is printed and folowed by a return (the \n).
2. NF - this is awk for the number of fields. In awk the standard delimeter for a field is whitespace, so in your example the simple space separates each field
3. x+=2 - step through loop in units of 2 as we wish to print pairs of information
4. $(x + 5) - the $ is similar to the one in bash that it evaluates and in this case it will evaluate the fields we wish to look at - first being 5 and 6
5. , - seems funny to comment on a comma but in awk this will enable print to output the OFS (output field separator), the standard being a space
So overall it says - loop through each line of the file and starting at positions 5 and 6 print the two fields separated by a space
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.