• Frode Nescafen (unregistered)

    First out

  • Dave-Sir (unregistered)

    TMTOWTDI

    Not spam, Askimet

  • Abdu (unregistered)

    Frist! PS: Not spam...

  • Anonymous Coward (unregistered)

    But this version supports platforms where wc doesn't have -l.

  • (cs)

    Oh great, I can hear the stampede of linux geeks waddling to their keyboards now...

  • Windozer (unregistered) in reply to C-Octothorpe
    C-Octothorpe:
    Oh great, I can hear the stampede of linux geeks waddling to their keyboards now...

    What's a wc? What's a perl? Why do all of these backslashes go the wrong way? What's going on? HALP ME, I DON'T UNDERSTAND!!!

  • (cs)

    The final line of this comment was supposed to be my whole comment, but apparently it looks like spam to some algorithm:

    Man!

  • justsomedude (unregistered) in reply to Windozer
    Windozer:
    C-Octothorpe:
    Oh great, I can hear the stampede of linux geeks waddling to their keyboards now...

    What's a wc? What's a perl? Why do all of these backslashes go the wrong way? What's going on? HALP ME, I DON'T UNDERSTAND!!!

    It's okay dear. Here, come sit down and play some minesweeper.

  • F (unregistered)

    "... the author thought to use the wc command but not the -l option."

    It's for flexibility. If you want to change it to report characters instead, you only need to change the parameters to cut, instead of having to replace wc -l with wc -c.

  • (cs)

    It's obvious, can't you see? wc -l puts all those spaces on the front of the output, and you need all that gubbins to get rid of them!

    It's not like this could do the job, is it?

    wc -l < /var/run/netstat_r.lst | tr -d ' '

    or even

    wc -l < /var/run/netstat_r.lst | sed "s/ //g"

    And no, I'm not a Linux geek. I'm a FreeBSD geek.

  • simple (unregistered) in reply to Windozer
    Windozer:
    C-Octothorpe:
    Oh great, I can hear the stampede of linux geeks waddling to their keyboards now...

    What's a wc? What's a perl? Why do all of these backslashes go the wrong way? What's going on? HALP ME, I DON'T UNDERSTAND!!!

    Never have I wanted to 'upvote' a reply more than I do now...

  • kktkkr (unregistered)

    Counting lines is easy: Minus, Slash and Backslash - 1 Plus, Equals, Less Than, T - 2 Asterisk , H, K, F - 3 Octothorpe - Many.

  • anon y mouse (unregistered)

    This smacks of someone doing something I WISH I had done to someone.

    I was asked in a chatroom at work in all seriousness:

    "Where is the /etc/hosts file??"

    I wish my response had been as convoluted as that approach above....

  • (cs)
    "Not long ago, I was poking around one of our production web servers and noticed the following curiosity in a shell script," writes Marshall G.
    /bin/cat /var/run/netstat_r.lst | /usr/bin/wc | /usr/bin/cut -b -8 |perl -e 'my $r=<>; $r =~ s/^\s+//; print "$r"'

    "Since the command only counts the number of lines in netstat_r.lst, I'm perplexed at the complexity of this approach."

    "Especially since the author thought to use the wc command but not the -l option."

    TRWTF is um perl?

  • (cs) in reply to simple
    simple:
    Windozer:
    C-Octothorpe:
    Oh great, I can hear the stampede of linux geeks waddling to their keyboards now...

    What's a wc? What's a perl? Why do all of these backslashes go the wrong way? What's going on? HALP ME, I DON'T UNDERSTAND!!!

    Never have I wanted to 'upvote' a reply more than I do now...

    Right on queue: the circle-jerk begins.

  • (cs) in reply to dohpaz42
    dohpaz42:
    TRWTF is that Marshall G. didn't realize that this complex approach does not count lines that only contain whitespace; something that wc -l is not capable of doing.

    So what you are saying is... there is no WTF, except for the OP not understanding the requirements of the script?

  • Hortical (unregistered) in reply to C-Octothorpe
    C-Octothorpe:
    simple:
    Windozer:
    C-Octothorpe:
    Oh great, I can hear the stampede of linux geeks waddling to their keyboards now...

    What's a wc? What's a perl? Why do all of these backslashes go the wrong way? What's going on? HALP ME, I DON'T UNDERSTAND!!!

    Never have I wanted to 'upvote' a reply more than I do now...

    Right on queue: the circle-jerk begins.

    Is yours just a one-man party?

  • (cs) in reply to KattMan
    Kattman:
    So what you are saying is... there is no WTF, except for the OP not understanding the requirements of the script?
    Actually TRWTF was my knee-jerk reaction trying to state a WTF, by forgetting that the input to perl is the output of wc. I've since updated my comment, but sadly not before you quoted me. :)
  • Warren (unregistered)

    Couldn't you just determine the average number of characters per line and then divide the file size by this?

    No I have realised this would only work if your characters were always one byte.

  • jarfil (unregistered) in reply to Steve The Cynic
    Steve The Cynic:
    It's obvious, can't you see? wc -l puts all those spaces on the front of the output, and you need all that gubbins to get rid of them!

    Don't know about BSD, but GNU's wc puts no spaces with -l. Also, it takes an input file as a parameter, so no need for pipes:

    /usr/bin/wc -l /var/run/netstat_r.lst

    Now, all this "could" be not such a WTF if /usr/bin/wc was some kind of redirect like from busybox or the likes, that wouldn't support the -l option... although whether it would be possible to run perl in such case, kind of baffles me.

  • (cs) in reply to Hortical
    Hortical:
    C-Octothorpe:
    simple:
    Windozer:
    C-Octothorpe:
    Oh great, I can hear the stampede of linux geeks waddling to their keyboards now...

    What's a wc? What's a perl? Why do all of these backslashes go the wrong way? What's going on? HALP ME, I DON'T UNDERSTAND!!!

    Never have I wanted to 'upvote' a reply more than I do now...

    Right on queue: the circle-jerk begins.

    Is yours just a one-man party?

    Of course! What, is there something else you're supposed to do while at work?

  • cihv (unregistered) in reply to Windozer

    I don't work with toilets on the command line so I count lines with awk:

    awk '{lines++}END{print lines}' <filename>
  • C-Octothorpe (unregistered) in reply to Hortical
    Hortical:
    C-Octothorpe:
    simple:
    Windozer:
    C-Octothorpe:
    Oh great, I can hear the stampede of linux geeks waddling to their keyboards now...

    What's a wc? What's a perl? Why do all of these backslashes go the wrong way? What's going on? HALP ME, I DON'T UNDERSTAND!!!

    Never have I wanted to 'upvote' a reply more than I do now...

    Right on queue: the circle-jerk begins.

    Is yours just a one-man party?

    There's not much else to do where I live.

  • (cs) in reply to Windozer
    Windozer:
    What's a perl?
    I can find all the perls I need here.
  • (cs)

    I don't see why he couldn't have just read the manual page for wc to find out what options it supported. It's as easy as typing

    echo | gunzip -c $(find /usr/share/man -name 'wc\.*' | head -1 |awk '/wc/ { print $1}' | tail -1 ) | sed '' | /usr/bin/groff -mtty-char -Tutf8 -mandoc | cat -u | pager -s

    Seriously, what is wrong with people?

  • Pr0gramm3r (unregistered) in reply to Steve The Cynic
    Steve The Cynic:
    It's obvious, can't you see? wc -l puts all those spaces on the front of the output, and you need all that gubbins to get rid of them!

    It's not like this could do the job, is it?

    wc -l < /var/run/netstat_r.lst | tr -d ' '

    or even

    wc -l < /var/run/netstat_r.lst | sed "s/ //g"

    And no, I'm not a Linux geek. I'm a FreeBSD geek.

    Same shit different pile.
  • Hortical (unregistered) in reply to C-Octothorpe
    C-Octothorpe:
    Hortical:
    C-Octothorpe:
    simple:
    Windozer:
    C-Octothorpe:
    Oh great, I can hear the stampede of linux geeks waddling to their keyboards now...

    What's a wc? What's a perl? Why do all of these backslashes go the wrong way? What's going on? HALP ME, I DON'T UNDERSTAND!!!

    Never have I wanted to 'upvote' a reply more than I do now...

    Right on queue: the circle-jerk begins.

    Is yours just a one-man party?

    Of course! What, is there something else you're supposed to do while at work?

    You have a job?!?! Someone pays you?!?!

  • (cs) in reply to dohpaz42
    dohpaz42:
    TRWTF is um perl?

    Too right! The correct approach is obviously:

    /bin/cat /var/run/netstat_r.lst | /usr/bin/wc | /usr/bin/cut -b -8 | awk '{print $1;}'

  • (cs) in reply to Hortical
    Hortical:
    C-Octothorpe:
    Hortical:
    C-Octothorpe:
    simple:
    Windozer:
    C-Octothorpe:
    Oh great, I can hear the stampede of linux geeks waddling to their keyboards now...

    What's a wc? What's a perl? Why do all of these backslashes go the wrong way? What's going on? HALP ME, I DON'T UNDERSTAND!!!

    Never have I wanted to 'upvote' a reply more than I do now...

    Right on queue: the circle-jerk begins.

    Is yours just a one-man party?

    Of course! What, is there something else you're supposed to do while at work?

    You have a job?!?! Someone pays you?!?!

    If by job you mean laid-off and by pay you mean UI, then yes, I have a paying job...

  • Hortical (unregistered) in reply to C-Octothorpe
    C-Octothorpe:
    Hortical:
    C-Octothorpe:
    Hortical:
    C-Octothorpe:
    simple:
    Windozer:
    C-Octothorpe:
    Oh great, I can hear the stampede of linux geeks waddling to their keyboards now...

    What's a wc? What's a perl? Why do all of these backslashes go the wrong way? What's going on? HALP ME, I DON'T UNDERSTAND!!!

    Never have I wanted to 'upvote' a reply more than I do now...

    Right on queue: the circle-jerk begins.

    Is yours just a one-man party?

    Of course! What, is there something else you're supposed to do while at work?

    You have a job?!?! Someone pays you?!?!

    If by job you mean sitting at an internet cafe and by pay you mean not pay, then yes, I have a paying job...

    So your life consists of jerking off in an internet cafe while talking to my many sockpuppets in comments threads on TDWTF.

    I'll let that sink in.

  • PleegWat (unregistered) in reply to anon y mouse

    It is at C:\WINDOWS\SYSTEM\drv\etc\hosts

  • Jorrit (unregistered) in reply to Steve The Cynic

    Uhm, there are no formatting spaces when you do:

    wc -l < FILENAME

    But I suppose it's always a good idea to remove them. Just in case.

  • (cs) in reply to Hortical
    Hortical:
    So your life consists of jerking off in an internet cafe while talking to my many sockpuppets in comments threads on TDWTF.

    I'll let that sink in.

    YHBT YHL HAND

    I'll let that sink in.

  • (cs) in reply to PleegWat
    PleegWat:
    It is at C:\WINDOWS\SYSTEM\drv\etc\hosts
    Not since Monkey Boy put the stake in the heart of Windows Me it's not.

    %WINDOWS_DIRECTORY%\SYSTEM32\drivers\etc\hosts

    YMMV on x64 systems.

  • (cs) in reply to Jorrit
    Jorrit:
    Uhm, there are no formatting spaces when you do:

    wc -l < FILENAME

    But I suppose it's always a good idea to remove them. Just in case.

    On FreeBSD, wc -l displays spaces in front of the number, and if you give it filename args, it displays the name(s) after the numbers.

    So just in case you aren't using GNU tools.

  • (cs)

    CAN YOU SEND ME THOSE CODEZ TO MY AOL? I WANT TO HAK MY EX'S EMAL.

    -SCRIPTKIDDIE29923

  • Chris (unregistered)

    So... apparently this should return more than just the line count:

    ~$ wc /etc/hosts|cut -b -8
      9  26 
    
  • David (unregistered) in reply to KattMan

    Still could've done that much better:

    /bin/sed '/^\W*$/d' /var/run/netstat_r.lst | wc -l

    Could probably write an awk script that wouldn't need the pipe, but this is quite a bit more readable (if you're going to use regex's anyways).

  • Hortical (unregistered) in reply to C-Octothorpe
    C-Octothorpe:
    Hortical:
    So your life consists of jerking off in an internet cafe while talking to my many sockpuppets in comments threads on TDWTF.

    I'll let that sink in.

    YHBT YHL HAND

    I'll let that sink in.

    Hmmm...

    You admit to being an expendable loser (laid-off) with a narrow scope of expertise (doesn't understand unix) and I'm supposed to feel like the joke's on me?

    If it keeps you from killing yourself and entertaining us all day, I guess I'm fine with that.

  • (cs) in reply to Steve The Cynic
    Steve The Cynic:
    %WINDOWS_DIRECTORY%\SYSTEM32\drivers\etc\hosts

    YMMV on x64 systems.

    Actually, IIRC, for historical reasons, Win64 still keeps all the relevant 64-bit libraries, etc. in the System32 folder.

    For maximum fun, the 32-bit compatibility libraries are stored in the WoW64 folder...

    Figure that one out...

  • tk421 (unregistered) in reply to C-Octothorpe
    C-Octothorpe:
    Hortical:
    So your life consists of jerking off in an internet cafe while talking to my many sockpuppets in comments threads on TDWTF.

    I'll let that sink in.

    YHBT YHL HAND

    I'll let that sink in.

    Your terrible life is a troll? Or your pretending to have a terrible life is a troll? Or the fact that he's trolling you is a troll?

  • (cs) in reply to Hortical
    Hortical:
    C-Octothorpe:
    Hortical:
    So your life consists of jerking off in an internet cafe while talking to my many sockpuppets in comments threads on TDWTF.

    I'll let that sink in.

    YHBT YHL HAND

    I'll let that sink in.

    Hmmm...

    You admit to being an expendable loser (laid-off) with a narrow scope of expertise (doesn't understand unix) and I'm supposed to feel like the joke's on me?

    If it keeps you from killing yourself and entertaining us all day, I guess I'm fine with that.

    Well, the joke is on you because if you're too up-tight to recognize an obvious joke, then I feel really bad for you...

    Don't let me get in the way: nerd on brother!

  • (cs) in reply to C-Octothorpe
    C-Octothorpe:
    nerd on brother!
    Hehe
  • EvilSpudBoy (unregistered) in reply to anon y mouse

    You could have told him, "I'll send it to you." And then send, via interoffice, a manila folder labeled /etc/hosts containing a typewritten list of host names.

  • trtrwtf (unregistered) in reply to C-Octothorpe
    C-Octothorpe:
    Don't let me get in the way: nerd on brother!

    Mr. Kettleblack, there is a call for you, a Mr. Pot is on the line.

  • Nagesh (unregistered)

    C-Octomom's "jokes" are a crime against comedy.

  • trtrwtf (unregistered) in reply to trtrwtf
    trtrwtf:
    C-Octothorpe:
    Don't let me get in the way: nerd on brother!

    Mr. Kettleblack, there is a call for you, a Mr. Pot is on the line.

    Not everybody can be a dashing, sexy wordsmith like yours truly.

  • SG_01 (unregistered) in reply to anon y mouse
    anon y mouse:
    "Where is the /etc/hosts file??"

    In C:\Windows\System32\Drivers of course ;)

  • Too Lazy To Sign In (unregistered) in reply to random_garbage

    Well, WoW64 does make a twisted kind of sense if you write it out - Windows on Windows64.

  • davee123 (unregistered)

    This isn't a WTF, it's job security!

    DaveE

Leave a comment on “How Not to Count Lines”

Log In or post as a guest

Replying to comment #:

« Return to Article