Delimeters when using the "cut" tool.
Greg Hunt
hunt at dg-rtp.rtp.dg.com
Sat Apr 6 00:48:39 AEST 1991
In article <T2Q_XF#@ee.eng.ohio-state.edu>, juodvalk at ee.eng.ohio-state.edu (Vincent Vladas Juodvalkis) writes:
>
> ...
> Now my problem comes when I try to cut this line. If I just try to
> cut it by filed, trying to get the second field (50000), using the
> following
>
> quota -v 2>&1 | grep -v quota | grep -v / | cut -f2
>
> the output I get is
>
> 972 50000 50500 33 0 0
>
> Which is the same as before.
>
> The reason that I came up with for this is that the generic delimeter
> is a tab, and this seemed to imply that the spaces in the output were
> not tabs.
That's right. Cut's default delimiter is a tab, and that's part of
the problem. But ...
> So I tried using spaces as the delimeter. The code I osed
> looked like
>
> quota -v 2>&1 | grep -v quota | grep -v / | cut -d" " -f2
>
> the output I got was just a bank line. My hypothesis for this is that
> the cut cuts after the first space it encounters and returns all that
> ir finds until the next space it encounters (which in this case
> happens to be the very next character, thus returning a line with
> nothing in it).
Yup. You figured it out right.
> What I need is either a was to get rid of all the extra spaces, or
> maybe just a better way to cut up the lines.
>
> I would appreciate any suggestion.
I think it's time for you to learn about a more powerful tool for
this sort of thing. Cut works great for simple cases, but when it
gets to be a pain, I switch to using awk. Try using this command
line:
quota -v 2>&1 | <all the grep stuff> | awk '{print $2}'
Awk ignores the multiple spaces, and this should print out 50000,
which is what you're looking for. The $2 refers to the second field
in the input line.
You can do a lot more with awk than you can with cut, so when cut
doesn't cut it (oooooh - that was a baaaaad one), try awk. The man
page for awk (at least on my system) is pretty good, so take a look
at it and see what else you can do with it. Enjoy!
--
Greg Hunt Internet: hunt at dg-rtp.rtp.dg.com
DG/UX Kernel Development UUCP: {world}!mcnc!rti!dg-rtp!hunt
Data General Corporation
Research Triangle Park, NC, USA These opinions are mine, not DG's.
More information about the Comp.unix.questions
mailing list