Search string in file

Hello all,
All I'm trying to do is search a file for a string and print out that line.   That's it !   However, this seems hard to do it seems.  In linux, I use 'grep' which does exactly what i'm looking for.  But it seems like when i
use get-content or select-string, it doesn't preserve the carriage return at the end and then select-string puts the name of the file and the number where it found it ahead of the whole line.  I think I read that when it finds a line it puts it in and
array and treats the line as an object.  All I want to do is when I find a string in a line print the line and only that line - including the line return at the end. 
Thanks,
Chris

# PowerShell
$myvar=Get-Content aca.txt|Select-String 'Utah'
You cannot use linefeeds in the body of a mail message.
$message=Get-Content aca.txt|Select-String 'Utah' | Out-String
Send-MailMessage -body $message
¯\_(ツ)_/¯

Similar Messages

  • Searching strings in files

    Is there a way to search all files on a harddisk for containing a particular (text) string ?

    >Have you an idea how this behaves for binary files... are they ignored or also searched (and then probably wrong results delivered)
    As written, the find command will check any file on disk - text or binary, it doesn't matter.
    The egrep is only doing a pattern match, so it's possible that the specific sequence of characters (or, more correctly, bytes) appears in a binary file too.
    If you want to check only specific files then you need to extend the find command accordingly. man find gives a list of the other parameters you can pass to find

  • Urgent + Search a delimited file for more then one string

    Hi All
    Urgent please help I am trying to search a file for 2 different strings.
    This is how the command prompt will look like
    java match "-t|" -4 -f Harvey -10 -f Atlanta callbook.txtPlease help me with identifying how many search criterias have been entered on command prompt.
    "-t|" - denotes a delimiter
    -4 - denotes the field number
    -f - case sensitive
    Thanks

    Hi
    Thanks for your quick response and I apologise I will never put urgent on my posting again.
    C:\>java match "-t|" -4 -f Harvey -10 -f Atlanta callbook.txt
    This example lists records for Atlanta with first name Harvey.
    I am able to get one search criteria but when I have 2 as above (Harvey and Atlanta) I get lost I do not know how to get these arguments from the commandline and still do a search correctly. My code at the moment is doint a hard coded search so I was trying to extract the arguments that's where I got stuck.
    The main aim of my app is to search a delimited file for a search criteria passed through a command prompt.
    This is what I have done so far.
    import  java.io.*;
    import java.util.*;
    public class assess1
        static public void main(String args[])
            int[] totals = new int[10];
            try
                BufferedReader inFile = new BufferedReader(new FileReader(args[0]) );
                try
                    String line;
              String StrSearch = "HARVEY";
              int counter = 0;
                    boolean foundIt = false;
                    while((line = inFile.readLine()) != null)
                     // search for the string
                      String[] values = line.split("\\|");
                       for (String str : values) {
                   if (str.equals("HARVEY")) {
                               System.out.println(line);
                             System.out.println();
                        counter++;
              if (counter == 0) {
                   System.out.println("String not found");
              inFile.close();
                catch(IOException e)
                    System.err.println("IO exception");
                    System.exit(1);
                catch(NumberFormatException e)
                    System.err.println("Value " + e.getMessage() + "not numeric");
            catch(FileNotFoundException e)
                System.err.println( "Couldn't open " + e.getMessage() );
                System.exit(1);
    }

  • Search a string in file

    I want to search for a string in file. I can do it reading the file in line by line and search each line but that would be more expensive. Is there are any api/freeware library, which can help me to search for a string in file?
    - R

    You can eliminate the overhead of creting strings, and also of translating bytes to chars, but that's all you can do. Do not forget:
    Premature optimization is the root of all evil.
    Using ByteBuffer and java.nio could be the best. I do not believe there's a library doing exactly what you need - I suppose nobody really needs it and it's easy to do.

  • Search string in any type file of a specified folder(DW能查找任意类型文件中的源代码吗)

    If search a string in a unfrequent type file,we can add this type in DW's  MMDocumentTypes.xml.
    But if a project has many many different unfrequent type files,I hope DW can support search string in any type file of a specified folder.
    Can DW help me? I really love DW very very much.

    hello shweta,
    Here is a batch script that will do this for you:
    batch file begin ********************************************
    @ ECHO OFF
    :READFILE
    SET | FIND "SEARCH_STRING" source.txt > NUL
    IF ERRORLEVEL 1 GOTO READFILE
    IF ERRORLEVEL 0 GOTO END
    sleep 5
    GOTO READFILE
    :END
    batch file end ***********************************************
    here, SEARCH_STRING is the string that will be searched in file source.txt. This SEARCH_STRING denotes the end of file (the file is ready to be transferred).
    This batch file should be called from PI "Run OS command before processing of the message".
    I tried this on my system and it worked for me.
    Just check at your end. I hope this will solve your query.
    Regards, Gaurav.
    Edited by: Kr.gaurav on Sep 9, 2010 3:54 PM

  • Search String in PDF file - MAC Apple Script

    I want to write a Script for Searching String in a PDF File.
    I start with Apple Script and the last 2 days i searching to eliminate the error in the Script.
    set Datei to choose file
    tell application "Adobe Acrobat Professional"
    open Datei
    activate
    find text Datei string "01.07.08"
    end tell
    The script will stopped in line from find text.
    The scrippt will be load a PDF file, activate it an i want to search "01.07.08" and marked it.
    Please help me.
    Thanks michael

    Right, I think I've got on to something here:
    1. I must not have been able to search this particular pdf document in the past, despite what I think I remember.
    2. When I select the Yamaha TDM pdf in Finder and show the Inspector window (CMD-opt-I) I see under "More Info" that Security Method is 'Password Encrypted'. In fact, try to select and copy some of the text: you can't. BUT: print the whole file to a new PDF, then save that new pdf file and use it for searching, ... ta-da! it works!
    I was a bit disappointed in ColorSync's inability to open the file and then Save it As... In the Tiger days, I had used this work-around: I took a password encrypted pdf document, opened it in ColorSync utility (in Applications/Utilities) and saved it under a new filename somewhere on the disk, and this process sort of neglected to cloak it up in its password-protection.
    Oh well, I suppose I can use the Print to PDF method which I describe just here to achieve the same goal. Until, that is, the big-wigs in the publishing companies and Apple are alerted to this fact and strip the 'functionality' from the print process.
    Thanks for posting.

  • Can't search contents of files only file names.

    I am really stuck guys. It's been aggrevating me for days. I tried to download 3rd party programs for searching in files and it still doesn't work. I checked the forums here and people only have trouble searching for kinds of files. Even when I use search strings like "contents" or "description" it still will only look for file names not contents.
    It's frustrating because I am typing up my own personal book and I am in the process of fixing all the mistakes which requires searching by contents in my folder where my files are stored!
    Thanks in advance!

    I've tried various file types.
    I tried adding my HD to the list and literally waited 1 minuted but to no avail.
    The next step is probably reinstalling Snow Leopard, right?
    By the way, I mostly use Finder for searching, so how would I enable the indexing there? Or is it only spotlight that has this indexing thing?

  • Two finger swipe replaces google search string

    MBP with Safari 6.0 experiencing this problem.  Another user was experiencing the issue here:
    http://www.ehmac.ca/mac-iphone-ipad-ipod-help-troubleshooting/99937-safari-two-f inger-swipe-bug-replaces-google-search-string-os-10-7-3-a.html
    I don't know where the bug reports are to follow up on it and I haven't seen any patches for it.  Any advice?  Specifically, I'd like to know how to file the bug (in case I find another) and to follow up on any existing issues.
    TIA,
    Scott

    Is there no place to track the status of the report or see any other outstanding issues so I don't bother filing duplicates?
    Never heard of such a function here. This method gets feedback to the people who count but it is completely behind the scenes. Part of Apple's "cards close to the chest" method of doing pretty much everything. You should have been looking at the "don't expect a response" screen after you hit the submit button on your bug report.
    If there is something that needs clarification, I suspect they will use e-mail to ask for it, but don't stay home waiting!
    Have you read Walter Isaacson's  biography of Steve Jobs? Things like this took on a new--if not satisfying--perspective for me after reading it. So far, it has persisted in their corporate culture in the after-Steve era..

  • Incremental search in java files

    Hi,
    i m supposed to write an application for Incremental Search in the Java Files.
    it is such that, u type a word, then go on hitting any spl key as F3..it should take u to the every next occurance of the word in the current file and highlight it....
    any one who has done b4, doing or knows abt this ......
    plzzzz hlp me..
    thanx in adv
    SK

    Hi,
    Just giving you an idea to solve this, but implementation of this depends on your hardwork.
    We can use Threads concept here. Use a integer variable, which is a global and is used later.
    Now TWO java threads are activated.
    One of the thread will constantly pool the Standard Input device for desired key value. Once it gets the desired key press value it will increment the integer variable.
    The Second thread will serve as the searching thread. This will contantly check the value of the integer variable and the search string variable. If the integer value is more than 0, then this thread will run a methos which will point to the next occurance of the search word. After this it will decrement the value of the integer variable.
    You may need to use Synchronization concept also in this when it comes to integer variable.
    Hope this idea helps.
    Do let me know once u implement the solution.
    Cheers.

  • Search Strings

    HI
    We are using Payment Order and through EBS we clear the vendor open items as after payment run system generate the payment order number but vendor open items remain open. For Bank Transfer BTC is NTRF. But for all the check which are also enchashed at counter bank is also using BTC NTRF. So we have two posting rules for the same BTC. For payment order clearing we are using Algoirtham 029. which is assigned in EBS global setting. To solve above we define the search strings but system is not changing the posting rule as check number coming immediately after NTRF1013.
    Our Check Number is exactly 4 characters. So we define search string like below
    Maping empy
    In search strings use we entered CC, HB, AC then algoritham999 as 029 is not exits then search string target field Posting rule and enter posting rule for check then create another entry in which target field is Algoritham and select algoritham 011 for check.
    Now our file for check is coming like 61:1201230123D10000,00NTRF1013       but system not read this record.
    Just for testing we make another line and like 61:1201230123D10000,00NTRF1013       //1013 and system able to change the Posting rule. No idea why its is behaving like this way
    Please help
    Farhan Qaiser

    Dear Farhan,
    Please create the search string in below way.
    (^ |#| *)NTRF####( *|$) with remaining parameters you have entered, please make sure that you are entering global interpretation algo in search string also.
    Or please check any other text is there to identify check transaction and create a search string for that.
    Regards
    Shanu

  • Is there a function to Search a Text File?

    I am writing a program that will read data from a URL and then save that URL to a text file. I then need to be able to search the text file for certain strings and must know which line they appear on. I realize that I could read the text file in line by line looking for the string and then note the current line number. However, I need to search for 20-30 different strings in each URL and this would be very inefficient. I would really like some way to say:
    int lineNumber = 0;
    lineNumber = searchText("sometextfile.txt", str);
    And have searchText return the lineNumber on which the String str was found. Alternately, if there is way to search a URL that would cut out the middle man of writing it to a text file first.
    Any help would be greatly appreciated as I could not find this anywhere. Thanks.

    I have done something similar to to this, but it depends on what you want to use it for. I was looking for specific data on websites and would copy that data into a database. So, I used regex to find the data on the site and copy it. I also had to use String Tokenizer in certain places to get the correct data sometimes.
    orozcom

  • How to search for a file?

    Hi I am currently using the below code to detect a file automaticaly in a thumbdrive. So currently I have to state the path directory to detect the particular file. Is there a way to search for the file in the thumbdrive using Java?
    public class Detect {
    public static void main(String[] args)
    File f = new File("f:\\");
    while (! f.exists())
    try { Thread.sleep(500); }
    catch (InterruptedException e) {}
    System.out.println("drive inserted!");
    }

    You'll need to recursively search through a top directory and all its subdirectories for all files. Here is a link how to do this.
    http://www.javapractices.com/Topic68.cjp
    You can search for all drives A through Z for the file (using something like new File("F:") and catching the exception if not found (and dont do anything with the exception). But exclude C and D drive since they are usually hard drives and take forever to search through. Also, you may want to use File.separator instead of '/" or '\' in your code since windowsXP uses one while Unix uses the other and you would want your code to be able to run on either operating system.
    Are you building a web page with this? if so, it will not work since your search code would be running on the server and not on the client's machine. Even if you were able to run it on the client machine via his browser, you cant because of security reasons (end users dont want to give you access to thier drives). If its a web page, look into file upload html tag called <input type="file". This allows the end-user to navigate on his machine to where the file is and download it without you having to search for it.
    If you writing an application instead of a web page, I think there is an applet you can use that will do the same thing as <input type="file".
    Searching though a directory structure isn't good since it takes too long for users t wait.

  • How does full-text search for pdf files work?

    Hi there,
    Basically I can see my pdf file in the content server.. inside the pdf there's a piece of test that says: "Test's Sample" but when I do a search with that string the file gets filtered from the results.
    I think it has to do with the ' (single quote) being there because other text in the pdf works fine.. so I was wondering how does VDK store this full text? where? I'd like to see how it gets translated IF that's how it works with pdf files....
    Following advice from Re: Parse error with search query I tried doing the search by:
    Test\'s Sample
    Test`s Sample
    "Test's Sample"
    The database is db2 if that helps.. how can I fix this problem?

    Nevermind, I fixed it by changing the VDK filters (in case someone is looking for a solution too).
    Cheers,

  • Searching a text file and printing the line if found!

    Hi, Im fairly new to JAVA and have been googling this for hours and havent found any results that
    have helped me...
    Im looking to search a text file for a value that is in a that is delimited by colons
    eg 45787 : 398948 : 398884 : 398984
    IF that value is found I need to print this entire line and move it into a string.
    I can work out the delimit part, the problem for me is a)searching the text file
    and b) tell java to print that line only??
    Any help would be very very much appreciated
    Cheers
    James

      public void printCourses() throws Exception
                stuinput[] courseObjArray = new stuinput[10]; //Make sure this is the same as the ammount in the text
                   Scanner sc = new Scanner(new File("testfile.txt"));
                   int i=0;
                   boolean found = false;
                   while(sc.hasNextLine())
                   //Delimit this line with scanner
                   Scanner sc1 = new Scanner(sc.nextLine());
                   sc1.useDelimiter(":");
                   courseObjArray[i] = new stuinput(sc1.next(),sc1.next());
                   i++;
                   }//while
                   for(int i1 = 0;i1 < courseObjArray.length;i1++)
                   System.out.println(courseObjArray[i1].courseCode);
                   System.out.println(courseObjArray[i1].courseName);
                   System.out.println(courseObjArray[i1].courseName);
                   System.out.println("-----------------");     
                   String courseCode2 = "courseObjArray[i1].courseCode";
                   if (courseCode2  == "12345")
                        System.out.println("working");
                   else{System.out.println("Not Found");}
           }hmmm just wondering why could this method always return a "Not Found"....if the text file had a whole bunch of values like this
    12345:Course1
    12344:Course2
    12343:Course3
    isnt it surposed to return 1 "Working"?? because there is a 12345 in on of the line, in the semi colon delimited line with 2 values, one being the course code, one being the course name??
    Given that there is 10 lines (from Array Object)

  • Searching for a file in DOS

    Hello, I'm trying to write a program that given the name of a file to the console, will search the file system looking for one or more files that match the provided name, and the output shows the full path to the found file.
    What would be the easiest way to do this? Thanks for any help.
    So far, i have this code:
    import java.io.File;
    public class FileList {
        public static void main(String args[]) {
            File baseDir = new File("C:/");
            File[] files = baseDir.listFiles();
            for (int i = 0; i < files.length; i++) {
                if (new File(("" +files)).isFile()) {
    System.out.println("File : " +files);
    else {
    System.out.println("Directory : " +files);

    I'm having the same problem as the person that was needing help with this topic. I get the error: Exception in thread "main" java.lang.NoClassDefFoundError: FindFile/java
    I don't know why. I looked at what you said would fix the problem, but that seems to not be doing the trick. Can you test this code for me and let me know how to get it to work. It's for a Java project and I'm havin g a tough time with it. Thank You.
    import java.io.*;
    import java.awt.*;
    class FindFile{
    public static void main(String args[]) throws IOException{
    BufferedReader userInput;
    while(true){
    userInput = new BufferedReader(new InputStreamReader(System.in));
    String s = userInput.readLine();
    if(s.equals("/quit")){
    System.exit(0);
    else if(s.equals("")){
    System.out.println("Command Syntax: java ListFiles <filename>");
    System.out.println("<filename> - The full name of a file and extension (i.e., test.txt)");
    else if(userInput != null){
    String t = "c:";
    File f = new File(t);
    String[] files = f.list();
    char[] qwet;
    boolean test = false;
    for (int i = 0; i < files.length; i++){
    if(files.equals(s)){
    System.out.println("");
    System.out.println("File Found");
    System.out.print("The File Found at This Path: ");
    System.out.print(f.getAbsolutePath());
    System.out.println(files);
    test = true;break;
    if(test == false){
    System.out.println("File Not Found");

Maybe you are looking for

  • Any way to split library between multiple hard drives?

    I recently purchased an Apple TV and started 'really' using iTunes for all of my music and videos. Is there a way I can keep my music on my iMac's hard drive and my videos on an external without switching libraries and still keep it (at least the vid

  • Movies Purchased on ATV will not sync back to iTunes

    I've tried "Transfer Purchases" - no good. I've gone to Automatic Sync - no good. The movies and shows I've purchased on the ATV itself will not sync back to my iTunes library, but the movies I purchased from the computer will sync to the ATV. So ...

  • Converting date time string to double data

    I have to plot a bar chart. The VI accepts only 2-d double data. My X- axis is date timestamp and Y- axis is the double data. Bt I am unable to convert the timestamp value to double. Anyone can suggest anything ? Regards, Runjhun.

  • New Authorization Objects for latest releases

    Dear Colleagues, Do you happen to know how to find out the objects that should be added when using a role from a previous SAP version in a new one. That is, we have imported a role from a previous SAP version into our system and would like to update

  • Error making zabbix agent on OSX

    I am installing the 1.4.2 agent on a OSX 10.4.10 Server machine that has XCode installed. I have also encountered the same problem on 10.4.8 Server, 10.4.6 Server, and 10.3.8 Server. I ran the ./configure --enable-agent and it checked out fine, then