Good morning,
I am working hard to get a grip on regular expressions and
have tried working with them for the past few days to
accomplish my object. That objective is: to break apart
output from the 'quota -v' command and print it in an html
table. I am confident (thanks to the very helpful responses
of previous posters) that I can apply html tags to the
individual parts of the output once I have it broken apart with
regular expressions. The 'quota -v' command outputs:
Disk quotas for jjasinsk (uid 6722945):
Filesystem usage quota limit timeleft files quota limit
+ timeleft
/var/mail 10688 15360 16384 0 0 0
+
/export/home3
98386 307200 308224 2003 0 0
With the following code, I am able to remove all of the extra
white space and that weird newline that occurs after /export/home:
#!/usr/bin/perl
$input=`quota -v`;
$input =~ s/\/export\/home[1-5] *\n/\/home/;
$input =~ s/\s+/ /g;
$input =~ s/\/var/\n\/var/;
$input =~ s/\/home/\n\/home/;
$input =~ s/: /:\n/;
print $input;
The output of this code is:
Disk quotas for jjasinsk (uid 6722945):
Filesystem usage quota limit timeleft files quota limit timeleft
/var/mail 10688 15360 16384 0 0 0
/home 98386 307200 308224 2003 0 0
However, I am finding that, what used to be very simple in unix
is slightly more difficult in perl. I would like to "grep" for
and remove the first two lines of the output. Better yet, I would
like to store the first line in a variable so that I might display
things like the uid or the username somewhere else on my
html page.
I have read through various sources on regular expressions,
including one from "Perl Black Book", the online source
"Perl Regular Expression Tutorial," and have looked up information
on grep and egrep, but have had no luck in being able to separate
those first two lines from my output. If anyone here would
be gracious enough to give me a few pointers, I would be
very appreciative. Thanks for your time.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.