<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Possible ksh ${parameter##pattern}  substring? in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/possible-ksh-parameter-pattern-substring/m-p/2868904#M822280</link>
    <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Here's a 1 liner that works for ksh :-)&lt;BR /&gt;&lt;BR /&gt; $ a=shellprogrammingisneat&lt;BR /&gt; $ b=${a##shell} echo ${b%%neat}&lt;BR /&gt;programmingis&lt;BR /&gt; $&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;  JW.</description>
    <pubDate>Mon, 23 Dec 2002 01:27:16 GMT</pubDate>
    <dc:creator>John Wright_1</dc:creator>
    <dc:date>2002-12-23T01:27:16Z</dc:date>
    <item>
      <title>Possible ksh ${parameter##pattern}  substring?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/possible-ksh-parameter-pattern-substring/m-p/2868898#M822274</link>
      <description>Is there a way to combine&lt;BR /&gt;&lt;BR /&gt;${parameter##pattern} &lt;BR /&gt;&lt;BR /&gt;and&lt;BR /&gt;&lt;BR /&gt;${parameter%%pattern}&lt;BR /&gt;&lt;BR /&gt;to pull out a substring?  As in something like:&lt;BR /&gt;&lt;BR /&gt;${parameter##pattern%%pattern}&lt;BR /&gt;&lt;BR /&gt;or&lt;BR /&gt;&lt;BR /&gt;${parameter##pattern:parameter%%pattern}&lt;BR /&gt;&lt;BR /&gt;I've seen the forum item:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x69246049dbb6d611abdb0090277a778c,00.html" target="_blank"&gt;http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x69246049dbb6d611abdb0090277a778c,00.html&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;And indeed, &lt;BR /&gt;&lt;BR /&gt;$a=example&lt;BR /&gt;$echo ${a:5:6} &lt;BR /&gt;le&lt;BR /&gt;&lt;BR /&gt;Does seem to do as expected.  Any thoughts, gurus?</description>
      <pubDate>Fri, 20 Dec 2002 22:47:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/possible-ksh-parameter-pattern-substring/m-p/2868898#M822274</guid>
      <dc:creator>A. Daniel King_1</dc:creator>
      <dc:date>2002-12-20T22:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: Possible ksh ${parameter##pattern}  substring?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/possible-ksh-parameter-pattern-substring/m-p/2868899#M822275</link>
      <description>Sorry!&lt;BR /&gt;&lt;BR /&gt;I just realized that for the last:&lt;BR /&gt;&lt;BR /&gt;$echo ${a:5:6}&lt;BR /&gt;&lt;BR /&gt;I was in bash!  The question still applies, though - and extra points for those who can tell me how to do this in _bash_ as well!</description>
      <pubDate>Fri, 20 Dec 2002 22:50:55 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/possible-ksh-parameter-pattern-substring/m-p/2868899#M822275</guid>
      <dc:creator>A. Daniel King_1</dc:creator>
      <dc:date>2002-12-20T22:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: Possible ksh ${parameter##pattern}  substring?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/possible-ksh-parameter-pattern-substring/m-p/2868900#M822276</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I played with the pattern substitutions in both ksh and bash, and I don't think they will work as you show them.  They can't be combined on a single line, but you can split them into two lines.  Something like this will work:&lt;BR /&gt;&lt;BR /&gt;MYSTRING=mystring.txt&lt;BR /&gt;echo "MYSTRING=$MYSTRING"&lt;BR /&gt;MYSTRING=${MYSTRING##my}&lt;BR /&gt;MYSTRING=${MYSTRING{%%.txt}&lt;BR /&gt;echo "MYSTRING=$MYSTRING"&lt;BR /&gt;&lt;BR /&gt;will return&lt;BR /&gt;&lt;BR /&gt;MYSTRING=mystring.txt&lt;BR /&gt;MYSTRING=string&lt;BR /&gt;&lt;BR /&gt;You could probably write a function where you could pass the parameter (variable) and the patterns to it, and have it return the result to you.  The easier way would be to use 'awk' as shown in the thread you listed.&lt;BR /&gt;&lt;BR /&gt;This is one of those examples where you are trying to do something that is hard to do in ksh or bash, but is probably quite easy to do in Perl.&lt;BR /&gt;&lt;BR /&gt;JP&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 21 Dec 2002 04:56:07 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/possible-ksh-parameter-pattern-substring/m-p/2868900#M822276</guid>
      <dc:creator>John Poff</dc:creator>
      <dc:date>2002-12-21T04:56:07Z</dc:date>
    </item>
    <item>
      <title>Re: Possible ksh ${parameter##pattern}  substring?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/possible-ksh-parameter-pattern-substring/m-p/2868901#M822277</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;${${parameter##pattern}%%pattern}&lt;BR /&gt;&lt;BR /&gt;Don't know if it works, but you could give it a try...&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Vincent</description>
      <pubDate>Sat, 21 Dec 2002 17:21:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/possible-ksh-parameter-pattern-substring/m-p/2868901#M822277</guid>
      <dc:creator>Vincent Stedema</dc:creator>
      <dc:date>2002-12-21T17:21:48Z</dc:date>
    </item>
    <item>
      <title>Re: Possible ksh ${parameter##pattern}  substring?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/possible-ksh-parameter-pattern-substring/m-p/2868902#M822278</link>
      <description>Hi Vincent,&lt;BR /&gt;&lt;BR /&gt;I had tried your suggestion and ksh didn't like it:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/ksh&lt;BR /&gt;&lt;BR /&gt;# pattern.ksh&lt;BR /&gt;&lt;BR /&gt;MYSTRING=mystring.txt&lt;BR /&gt;echo "MYSTRING=$MYSTRING"&lt;BR /&gt;&lt;BR /&gt;MYSTRING=${MYSTRING##my}&lt;BR /&gt;STRING1=${${MYSTRING##my}%%.txt}&lt;BR /&gt;echo "STRING1=$STRING1"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Which gives this result:&lt;BR /&gt;&lt;BR /&gt;&amp;gt;./pattern.ksh                      &lt;BR /&gt;MYSTRING=mystring.txt                                                 &lt;BR /&gt;./pattern.ksh[9]: STRING1=${${MYSTRING##my}%%.txt}: bad substitution&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I tried it with some quote marks and it didn't like those either:&lt;BR /&gt;&lt;BR /&gt;STRING1=${"${MYSTRING##my}"%%.txt}&lt;BR /&gt;&lt;BR /&gt;./pattern.ksh[9]: STRING1=${"${MYSTRING##my}"%%.txt}: bad substitution&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;JP&lt;BR /&gt;</description>
      <pubDate>Sat, 21 Dec 2002 20:03:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/possible-ksh-parameter-pattern-substring/m-p/2868902#M822278</guid>
      <dc:creator>John Poff</dc:creator>
      <dc:date>2002-12-21T20:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: Possible ksh ${parameter##pattern}  substring?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/possible-ksh-parameter-pattern-substring/m-p/2868903#M822279</link>
      <description>John: Yeah, I know. Bash doesn't like it either... The problem is with the substitution: it returns the value of the substitution, instead of a variable with a substituted value.&lt;BR /&gt;&lt;BR /&gt;Daniel:&lt;BR /&gt;&lt;BR /&gt;Here's a multi-line solution which doesn't use temp variables, except for the patterns...&lt;BR /&gt;&lt;BR /&gt;p1="pattern1"&lt;BR /&gt;p2="pattern2"&lt;BR /&gt;${parameter:${#p1}:$(( ${#parameter} - ${#p1} - ${#p2} ))}&lt;BR /&gt;&lt;BR /&gt;Proof that it works:&lt;BR /&gt;&lt;BR /&gt;vincent@magnolia ~&lt;BR /&gt;$ a="shellprogrammingisneat"&lt;BR /&gt;&lt;BR /&gt;vincent@magnolia ~&lt;BR /&gt;$ p1="shell"&lt;BR /&gt;&lt;BR /&gt;vincent@magnolia ~&lt;BR /&gt;$ p2="neat"&lt;BR /&gt;&lt;BR /&gt;vincent@magnolia ~&lt;BR /&gt;$ echo ${a:${#p1}:$(( ${#a} - ${#p1} - ${#p2}))}&lt;BR /&gt;programmingis&lt;BR /&gt;&lt;BR /&gt;Don't know if this what you're looking for, though.&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;&lt;BR /&gt;Vincent</description>
      <pubDate>Sun, 22 Dec 2002 12:32:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/possible-ksh-parameter-pattern-substring/m-p/2868903#M822279</guid>
      <dc:creator>Vincent Stedema</dc:creator>
      <dc:date>2002-12-22T12:32:20Z</dc:date>
    </item>
    <item>
      <title>Re: Possible ksh ${parameter##pattern}  substring?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/possible-ksh-parameter-pattern-substring/m-p/2868904#M822280</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Here's a 1 liner that works for ksh :-)&lt;BR /&gt;&lt;BR /&gt; $ a=shellprogrammingisneat&lt;BR /&gt; $ b=${a##shell} echo ${b%%neat}&lt;BR /&gt;programmingis&lt;BR /&gt; $&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;  JW.</description>
      <pubDate>Mon, 23 Dec 2002 01:27:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/possible-ksh-parameter-pattern-substring/m-p/2868904#M822280</guid>
      <dc:creator>John Wright_1</dc:creator>
      <dc:date>2002-12-23T01:27:16Z</dc:date>
    </item>
    <item>
      <title>Re: Possible ksh ${parameter##pattern}  substring?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/possible-ksh-parameter-pattern-substring/m-p/2868905#M822281</link>
      <description>I've actually done some timings on shell-level extraction versus awk extractions.&lt;BR /&gt;&lt;BR /&gt;awk seems to be faster in most cases.&lt;BR /&gt;&lt;BR /&gt;I was interested, though, in pushing the limits of the shell, and I appreciate the thoughts you have expressed.&lt;BR /&gt;&lt;BR /&gt;I was a little surprised, though.  Somewhere I had read that, as a rule, calling external programs slows down a script, and that shell internals should be, generally speaking, faster.&lt;BR /&gt;&lt;BR /&gt;Live and learn, I suppose.</description>
      <pubDate>Mon, 30 Dec 2002 23:30:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/possible-ksh-parameter-pattern-substring/m-p/2868905#M822281</guid>
      <dc:creator>A. Daniel King_1</dc:creator>
      <dc:date>2002-12-30T23:30:15Z</dc:date>
    </item>
  </channel>
</rss>

