User Profile

Collapse

Profile Sidebar

Collapse
Elizabeth H
Elizabeth H
Last Activity: Nov 5 '12, 10:44 PM
Joined: Jan 18 '11
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Elizabeth H
    started a topic grep multiple commands
    in Perl

    grep multiple commands

    Hi

    Below is what I am trying to do. I have a variable which contains a list of commands seperated by ":". While trying to use a for loop to get each command, it doesnt retrun the correct results

    Example:

    Code:
    var="command -1:command -2*: command something*"
    for c in `echo $var | tr ':' ' '`
    do
      echo $c
    done
    
    Instead of getting the below
    command
    ...
    See more | Go to post
    Last edited by zmbd; Nov 5 '12, 08:08 PM. Reason: [Z(Please use the <CODE/> button to format your code)]

  • How to grep from multiple files given one of those files dont exist

    I am trying to grep for a particular word from two files like below. I need to find the word in one of the two files

    grep "myWord" file1 file2 && echo 1 or echo 0

    The issue is that I have to search in both the files, but sometimes one of these files doesnt exist. So even when the word is present in one of the files it stil returns a 0.
    See more | Go to post

  • Elizabeth H
    started a topic how to grep for an IP address
    in Perl

    how to grep for an IP address

    I wanted to grep the IP address from this following exception. What is the easiest way to do this?

    "var=something. something.somth ing.Exception : The IP xx.xxx.x.xxx cannot be used"


    I want to grep the IP address from this string and store it in a different variable. Do i just use the regular regex pattern to grep an IP address or is there an easy way
    See more | Go to post

  • Elizabeth H
    replied to Adding a new line after a pattern match
    in Perl
    Hi again

    I think I was able to figure out how to do it. But I came across a problem.This is what I tried
    sed -i -e '/^ # abcd/,/^ ## }}}$/s/ ## }}}/ $insert\n ## }}}/'
    If I use some string like "STRING" instead of the insert variable, it works perfectly fine. But when I try insert="for ....do...done" and try it with $insert it doesnt get substitued with the value of insert. I tried several different...
    See more | Go to post

    Leave a comment:


  • Elizabeth H
    started a topic Adding a new line after a pattern match
    in Perl

    Adding a new line after a pattern match

    Hi,

    I have a question regarding adding lines basically using sed after a pattern match. My code would look like

    Several lines in the file
    # abcd ##{{{
    variable 1
    variable 2
    variable 3
    .
    .
    .
    ## }}}

    And I need to add a for loop just before the 'abcd' fold closes and my new code shud look like
    Several lines in the file
    # abcd ...
    See more | Go to post

  • Elizabeth H
    replied to parse for a function definition
    in Perl
    @ROVF: I was told that perl might be a good way to do this...Since i dnt speak Perl much, it takes me more time to implement even the basic things, but you had got it right...I guess I was thinking it a bit too complex...Thnks again for ya quick responses and ya help
    See more | Go to post

    Leave a comment:


  • Elizabeth H
    replied to parse for a function definition
    in Perl
    Thnks alot..it wrks wellll....I dnt speak Perl much..so not much sure on how to modify.. can I have it in way where I can use this .pl file to call different files..and apply the same changes to all files(ie, parse out the specific fn in all files and add a trailing statement to all)? Again thnks for ya help!
    See more | Go to post

    Leave a comment:


  • Elizabeth H
    replied to parse for a function definition
    in Perl
    Thanks for the quick response. Like you had mentioned above, function braces are only in column 1, and the other braces are not in column 1 but not sure how to do the search I need to insert a new statement just before the closing curly brace of the function. Is function parsing the best way to do this or do I have any other option?
    See more | Go to post

    Leave a comment:


  • Elizabeth H
    replied to parse for a function definition
    in Perl
    Will you be able to still help me with the above question. I am still not able to parse the function correctly
    See more | Go to post

    Leave a comment:


  • Elizabeth H
    replied to parse for a function definition
    in Perl
    I tried what @rabbit mentioned , but didnt work. Guess it was coz I said the function doesnt have any braces inside it.
    See more | Go to post

    Leave a comment:


  • Elizabeth H
    replied to parse for a function definition
    in Perl
    I am sorry but it does have some braces inside the function.. so I dont know how to parse until the end of function
    See more | Go to post

    Leave a comment:


  • Elizabeth H
    started a topic parse for a function definition
    in Perl

    parse for a function definition

    I need to search for a particular function in a shell script and replace it with the modified function for which I can use sed inplace editor. But I am not able to correctly parse for the function. Can I have a regular expression to search for the function which is of the form
    function()
    {
    no other braces in between
    }
    See more | Go to post

  • Can I have some more clue on this as the function itself has several small blocks of statements with closing curly braces which makes it hard for me to parse exactly till end of function where I need to put my two variables
    See more | Go to post

    Leave a comment:


  • Thanks..lemme try
    See more | Go to post

    Leave a comment:


  • I also had another question. In the same scenario above, how do I set two variables VAR1 and VAR2(both used in function1) to blank at the end of function1(). Do i need to write a small script or if there is a one liner which can search for function1() and set those variables to blank at the end of the function. Thanks
    See more | Go to post

    Leave a comment:


  • Thanks a lot! :)
    See more | Go to post

    Leave a comment:


  • Thnks again...Could you please explain what it does..I especially the 1 and 2
    See more | Go to post

    Leave a comment:


  • That was such a great answer and worked really really well...Thankss a bunch..I have one more issue....In the above same problem..How do I insert the new string "ggg" exactly after the string "ccc" or so...is there a position based substitution?
    See more | Go to post

    Leave a comment:


  • Elizabeth H
    started a topic How to search and replace string using perl?
    in Perl

    How to search and replace string using perl?

    Hi,

    I had a few questions regarding searching for a string and replacing it using perl scripts. I have 100's of files written in Unix shell scripts and I need to edit them all. Its like
    Code:
    function1()
    { 
             variable=xxx
    }
     
    function 2()
    {
             variable='aaa bbb ccc ddd'
    }
    I have to search exactly for function 2 and only replace the variable in function...
    See more | Go to post
    Last edited by numberwhun; Jan 21 '11, 03:40 PM. Reason: Please use code tags!
No activity results to display
Show More
Working...