Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2006
    Posts
    31

    Unanswered: String extraction

    i have string of the type

    cp ${data_gdgd_tttt}/sedthr/dataOut/wasim_section.dat ${data_dddd}

    from where i want to extract the wasim_section.dat field.how do i do this?

    also in some cases the string could be of the type
    ${data_gdgd_tttt}/sedthr/dataOut/wasim_section.dat ${data_dddd}
    without the cp at the beginning.

    in such cases how do i achieve the same. i need a generic script that can handle any type of string. and I want to store these extracted portions in a variable.

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    Code:
    # echo $string1
    cp ${data_gdgd_tttt}/sedthr/dataOut/wasim_section.dat ${data_dddd}
    # echo $string2
    ${data_gdgd_tttt}/sedthr/dataOut/wasim_section.dat ${data_dddd}
    
    # basename $(echo $string1 | sed 's/cp //;s/${data_dddd}//')
    wasim_section.dat
    # basename $(echo $string2 | sed 's/cp //;s/${data_dddd}//')
    wasim_section.dat
    
    ### OR ###
    
    # echo ${string1##*/}|cut -d" " -f1
    wasim_section.dat
    # echo ${string2##*/}|cut -d" " -f1
    wasim_section.dat

  3. #3
    Join Date
    Feb 2006
    Posts
    31
    hey thanks man...its working gr8....... ;-)

  4. #4
    Join Date
    Feb 2006
    Posts
    31

    thanks

    hey thanks man its working gr8..... ;-)

Posting Permissions

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