Find the answer to your Linux question:
Results 1 to 4 of 4
what is the best command to use to parse strings? I have a variable $str and need to parse this string. Can you provide an example of the command used ...
  1. #1
    Just Joined!
    Join Date
    Feb 2010
    Posts
    14

    parsing strings

    what is the best command to use to parse strings?
    I have a variable $str and need to parse this string.
    Can you provide an example of the command used to get a substring of $str based on the index values of start and end

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    This is a feature built into Bash. See this page:
    Manipulating Strings

    Go to the section called "Substring Extraction".
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Just Joined!
    Join Date
    Feb 2010
    Posts
    14
    is there any other command. that I could use?...the expr is giving me lot of syntax issues....i just copied n pasted many different examples and most of them gave me a syntax error

  4. #4
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    For a positional substring, you shouldn't need expr at all...

    Code:
    bricka@eagle ~ $ string="foobar"; echo ${string:3}; echo ${string:2:2}
    bar
    ob
    You can use the ${STRING:START:LENGTH} syntax to accomplish this.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

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