Menu

Need some help to process a text file

Help
2005-03-08
2012-07-26
  • Nobody/Anonymous

    Hi, I need to find a Win32 command line tool to look for a string in a text file and output x number of characters from where it found the string. For example if the file contains:
    Post Comment Anonymously
    I want to search for Comment and pick 6 characters after that, resulting
    Anonym

    Is there any tool I can use to do something like this?

    Thanks and best regards,

    -Sam

     
    • Nobody/Anonymous

      Download sed-4.1.2-bin.zip, sed-4.1.2-dep.zip and sed-4.1.2-doc.zip, install it and then write

      sed -n ":x;s/^([^\n])Comment\s+([^\n]{0,6})[^\n]/\1\n\2/;tx;s/^[^\n]*\n//p" filename.txt

      in one line in a cmd windows. For more powerful text processing there is also the package gawk.

      HTH

       
MongoDB Logo MongoDB