Re: whats wrong with this grep?
begin Tim locke quotation:
> grep "..\/..\-..\:..\:" oos.txt | cut -d \> -f 1 |
> cut -d \ -f 2 | cut -d \: -f 1 | sed s/\ //g | sort |
> uniq -c | sort -nr > oos.log
How do you expect anyone to know what's wrong with it if you don't
tell us what you expect it to do?
The main comment I have about this thing is that it's nearly unreadable
because rather than properly quote things, you escape everything in
sight, including things that don't need to be escaped. The computer may
not care one way or the other, but humans attempting to read this are at
Here's something I think (without actually testing) is functionally
equivalent, but much easier to read:
grep '../..-..:..:' oos.txt | cut -d '>' -f 1 |
cut -d ' ' -f 2 | cut -d ':' -f 1 | tr -d ' ' | sort |
uniq -c | sort -nr > oos.log
So, what will this do?
Grep oos.txt for lines containing any two characters followed by a
slash, followed by any two characters, followed by a dash, followed by
any two characters, followed by a colon, followed by any two characters,
followed by another colon; matching lines are piped to cut, which
outputs only the text prior to the first greater-than; the result is
then piped to another cut, which outputs only the text between the first
and second space characters; then another cut, which outputs only the
text prior to the first colon; then all space characters are removed.
The final result of all this is then sorted, uniqued (with counts
added), sorted again (reverse, by frequency), and written to oos.log.
Whether this is what you want is quite unclear, since you didn't bother
to tell us what you want, or how the script is failing. The utter
lameness of that fact accounts for the poor temper of this reply.
A general note on script debugging: If you aren't getting what you want
out of a script, especially a complex pipe like this one, try testing
the individual components to figure out what isn't working. Just do the
grep, first. Do you get the lines you expect? If so, add the first cut,
then the second, and so on, confirming at each stage that you are
getting what you want.
To UNSUBSCRIBE, email to firstname.lastname@example.org
with a subject of "unsubscribe". Trouble? Contact email@example.com