unix help
Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: unix help

  1. #1
    Junior Member
    Join Date
    Jan 2008
    Posts
    6

    unix help

    1.
    i am trying to build a command that searches a text file
    and outputs the number of words which consists of two 'b' characters
    in each word separatly

    like
    barby

    (the b characters must be separated from one another)
    i tried to use grep [b][b] filepath
    then i know that we need to use pipe to count the result

    but it prints all the word with the two b chars
    one next to the other

    how do i build this command
    2.
    i am trying to build a command that searches a text file
    and outputs the number words which consists of two 'x' characters
    only
    i tried to use

  2. #2
    Just Another Geek
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,401
    man wc
    Oliver's Law:
    Experience is something you don't get until just after you need it.

  3. #3
    Junior Member
    Join Date
    Jan 2008
    Posts
    6

    i tried it the probles that

    now i can count them but i cant figure out
    how to filter out the undesirable words

  4. #4
    Senior Member
    Join Date
    Dec 2007
    Posts
    132
    I don't know of a command, but you can do this with a perl script.

    *dusting off perl skills*

    ...

    *dusting failed. using can of compressed air*

    Code:
    #!/usr/bin/perl
    $file = "testing.txt";
    
    open (CRAP,$file) || die "Can't open file '$file'. Reason: $!\n";
    @garbage = <CRAP>;
    close CRAP;
    
    foreach $i (@garbage){
     @words = split(/ /,$i);
     foreach $w (@words){
     chomp($w);
      # Uncomment one of the lines below for desired effect,
      # but make sure to comment out the one you don't want:
    
      # v Matches only letters between 2 b's. Uncommented as default.
      if ($w =~ /b[a-zA-Z]+b/i){
    
      # v Matches any alphanumeric characters between 2 b's
      #    (including numbers and _) ie, b1g_a55_b00ty
      # if ($w =~ /b\w+b/i){
          $count++;
          push (@results, $w);
        }
      }
     }
    
    if ($count<1){
    print "No results found.\n";
    
    }else{
    
    print "Found $count matches. Writing results to file 'results.txt' in this directory. \n";
    
    # This will overwrite results.txt if it already
    # exists. To simply append new results to the
    # existing file, change >results.txt to >>results.txt
    open (RES, ">results.txt") || die "Cannot open results.txt for writing. Reason: $!\n";
    foreach (@results){
    print RES $_;
    print RES "\n";
    }
    close RES;
    }
    Tested with a NYTimes article about baseball so I was able to debug a bit so the results file looks nice and clean.

    So, what did I do all this for? Why do you need to find 2 b's spaced apart? Just curious...

    Also, this will work for x's as well. Just change /b[a-zA-Z]+b/i to /x[a-zA-Z]+x/i

    If they need to be together and not seperate the you need to take out everything between the letters, ie: /xx/i

    The i means case-insensitve, so if you only want to look for XX or xx or Xx and not xX then take the i off.

  5. #5
    Junior Member
    Join Date
    Jan 2008
    Posts
    6

    i need it as a command

    i need it as a command

  6. #6
    Senior Member
    Join Date
    Dec 2007
    Posts
    132
    Oh, well excUUUUUUUUUUUse me sir,

    if ur running unix you can edit the script with filenames and run it at the command line. or you can rewrite it to accept filenames as args and use it as a command, not that hard. or you can just keep checking back and seeing if anyone has posted ur golden command.

    fuggin' beggers trying to be chosers...

  7. #7
    THE Bastard Sys***** dinowuff's Avatar
    Join Date
    Jun 2003
    Location
    Third planet from the Sun
    Posts
    1,251
    Quote Originally Posted by xiphias360
    Oh, well excUUUUUUUUUUUse me sir,
    fuggin' beggers trying to be chosers...
    Where the hell did I put the Neg-0-Matic 2000?

    Nice script x, I do have one question however, why did you write it? Really?
    09:F9:11:02:9D:74:E3:5B8:41:56:C5:63:56:88:C0

  8. #8
    Senior Member nihil's Avatar
    Join Date
    Jul 2003
    Location
    United Kingdom: Bridlington
    Posts
    17,191
    @ xiphias360:



    i need it as a command
    1. Go to your hardware store and buy a sledge hammer
    2. Preferably, but you need to be older than you sound: get a 9mm automatic weapon.
    3. Issue the command: "run this you feckin booger or die" Remember to raise the hammer/point the weapon before entering the command.

    Points to remember........... no matter what sort of OS or hardware you run,

    They DO NOT understand:

    1. Semtex
    2. C4/PE4
    3. Thermite
    4. Industrial strength corrosives

    So command lines including those statements won't work

  9. #9
    Senior Member
    Join Date
    Dec 2007
    Posts
    132
    cuz i knew it could be done quick & easy with perl, and to help this ungrateful tard. well no more mr. nice X...

    and what's a Neg-o-matic supposed to be? neg rep??

    OMG! It's neg rep! everybody RUUUUUUUUUUN!!!!!!!!!!!!!

    board points don't pay my car note, so im probably not gonna cry if i loose them, lol...

  10. #10
    Senior Member nihil's Avatar
    Join Date
    Jul 2003
    Location
    United Kingdom: Bridlington
    Posts
    17,191
    Nice script x
    I don't think that you were the target dinowuff had in mind?

Similar Threads

  1. Why one OS VS another isn't over played here
    By gore in forum Operating Systems
    Replies: 31
    Last Post: June 5th, 2006, 04:50 PM
  2. Basic Unix security tutorial
    By \/IP3R in forum AntiOnline's General Chit Chat
    Replies: 16
    Last Post: March 7th, 2005, 10:25 PM
  3. UNIX (Non tech)
    By gore in forum Operating Systems
    Replies: 1
    Last Post: October 12th, 2004, 08:29 AM
  4. Newbies, list of many words definitions.
    By -DaRK-RaiDeR- in forum Newbie Security Questions
    Replies: 9
    Last Post: December 14th, 2002, 08:38 PM
  5. UNIX is short for what?
    By Remote_Access_ in forum Security Archives
    Replies: 10
    Last Post: January 12th, 2002, 05:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •