Find the answer to your Linux question:
Results 1 to 2 of 2
So, I would like to recursively search through a set of files in multiple directories for a specific set of strings and then output the data to a .csv file. ...
  1. #1
    Just Joined!
    Join Date
    Jul 2010
    Posts
    2

    Recursive string search

    So, I would like to recursively search through a set of files in multiple directories for a specific set of strings and then output the data to a .csv file.

    For instance, I'm looking for things in .idl files formatted like:

    %msg_name{MSG_BLAH}
    %msg_length{MSG_LEN_BLAH}
    %msg_type{MSG_TYPE_BLAH}

    And then output the data within the braces into a .csv file.

    Looking for the files is just a matter of using find or awk, but I'm a bit lost from there, I think. Also, all the lines I need to look at are preceded by a "%," so that's how I'm searching for what I need.

    Any ideas oh wise folk? Thanks in advance!

  2. #2
    Linux Newbie
    Join Date
    Apr 2010
    Location
    Novosibirsk, Russia
    Posts
    136

    Smile

    Quote Originally Posted by Psykospot View Post
    So, I would like to recursively search through a set of files in multiple directories for a specific set of strings and then output the data to a .csv file.

    For instance, I'm looking for things in .idl files formatted like:

    %msg_name{MSG_BLAH}
    %msg_length{MSG_LEN_BLAH}
    %msg_type{MSG_TYPE_BLAH}

    And then output the data within the braces into a .csv file.

    Looking for the files is just a matter of using find or awk, but I'm a bit lost from there, I think. Also, all the lines I need to look at are preceded by a "%," so that's how I'm searching for what I need.

    Any ideas oh wise folk? Thanks in advance!
    you can write a simple perl script, that will consist only one subroutine with about 10 lines of code here all you need:
    'opendir' sub - see `perldoc -f opendir`

    'readdir' sub - see `perldoc -f readdir`

    file test operators : -d -f (ex. -d /usrdir returns true if usrdir is a directory, -f checks if argument is a regular file) - see `perldoc perlop`

    then, in general, you make a subroutine that reads current (start) directory and proceeds regular files. If it meets a directory, then subroutine calls itself with this directory as argument. Of course you should save working dirs and restore it inside the subroutine. So, that's all

Posting Permissions

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