Announcement

Collapse
No announcement yet.

Help with scanning a file for a string

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Help with scanning a file for a string

    I am looking to scan a file for particular strings to add to a command to be executed.

    The string will always be after a certain group of characters and between : and ).

    The string to be used in the command shows up multiple times in the file.

    I'm new to scripting.

    for instance:

    a;sdlkfjas;dlfksdj (fsfd: 1111111)
    asdasf
    ewrwea
    qawerws
    aswerwea (asf: 594830)

    I want 1111111 and 594830 to be added to the command. I'm sorry for not using correct terminology but I have forgotten many of the terms that I learned in Computer Science.

    just an example: sudo gedit 11111111

    I can't remember if you call them arguments but they are variables inside the function.


    Thanks

    #2
    Re: Help with scanning a file for a string

    not at my PC right now, but I wonder if you could use
    Code:
    | grep ":*)"
    ... I would have to look it up, but I know that you can read the file, and use grep to look for specific items in the file, and grep does support wildcards...

    I assume you are going to put this in a script.

    mm0
    Dell Inspiron 1720 Laptop<br />Intel T9300 Core2Duo Processor @ 2.5Ghz<br />4 GB Ram | 1920 X 1200 Resolution<br />2 X 160 GB SATA HD Internal<br />Nvidia GeForce 8600M Graphics Adapter<br />Using Kubuntu 9.10

    Comment


      #3
      Re: Help with scanning a file for a string

      I'm on a little bit of brain overload, but read this on grep.
      Dell Inspiron 1720 Laptop<br />Intel T9300 Core2Duo Processor @ 2.5Ghz<br />4 GB Ram | 1920 X 1200 Resolution<br />2 X 160 GB SATA HD Internal<br />Nvidia GeForce 8600M Graphics Adapter<br />Using Kubuntu 9.10

      Comment


        #4
        Re: Help with scanning a file for a string

        awk usually excels in these kind of tasks, but depending on the details you may get away with grep (and cut)

        EDIT:
        Here's a quick (and really ugly) grep method that should work provided that:
        1. the lines that your arguments are in end in '(*:*)' pattern (and other lines don't)
        2. there's only one colon ':' on those lines
        3. there's only one ')' after the colon on those lines

        Code:
        grep -e "(*:*)$" FILE_NAME | cut -d':' -f2 | cut -d')' -f1 | xargs sudo gedit
        (replace FILE_NAME with the actual file you wish to 'process'

        It's rather hard to give definite examples without knowing the exact details, so you may need to figure it out yourself...if you wish to have a look at awk (which is more elegant and powerful...but also comes with a learning curve. Definitely worth the time, though)
        These should get you started:
        http://www.gnu.org/software/gawk/manual/gawk.html
        http://www.softpanorama.org/Tools/awk.shtml

        EDIT2: toad's link is good too

        EDIT3: Improved grepping a bit

        Comment


          #5
          Re: Help with scanning a file for a string

          and here is the best intro to awk you could possibly imagine...

          http://www.vectorsite.net/tsawk_1.html#m1
          Once your problem is solved please mark the topic of the first post as SOLVED so others know and can benefit from your experience! / FAQ

          Comment


            #6
            Re: Help with scanning a file for a string

            Wow. Thanks so much for the help.

            I found http://blog.3v1n0.net/lista-reposito...kubuntu-linux/. Which is a list of repositories for Hardy, which I am running on a Desktop. In the list, he offers some keys that need to be installed. I'm trying to create a script to install the GPG keys quickly.

            So, read the GPG key, eg # Ubuntu supported packages (GPG key: 437D05B5)
            then using the key to run the commands to install them.

            This is the commands he says to use
            gpg –keyserver subkeys.pgp.net –recv KEY
            gpg –export –armor KEY | sudo apt-key add -

            THanks

            Comment


              #7
              Re: Help with scanning a file for a string

              I'd rather recommend against that...with a repository list like that I can almost guarantee things will break sooner or later (leaning towards sooner). The repository list includes a lot of 3rd party repos, including repos for other distributions...which means there will be package conflicts.

              My general instruction would be to keep the repository list to a minimum, basically sticking to the ubuntu repos, and possibly the PPA repos for packages not yet available through main ubuntu repositories (you can of course cherry pick extra repositories that you really need or want, but resist the urge to enable everything under the stars).

              There are also some security concerns when using 3rd party repositories.

              Comment

              Working...
              X