<?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: Pulling the first and last character/number from a string. in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/pulling-the-first-and-last-character-number-from-a-string/m-p/4217422#M91828</link>
    <description>&amp;gt; ...variable in the script...&lt;BR /&gt; &lt;BR /&gt;cat file | while read TEXT&lt;BR /&gt;do&lt;BR /&gt;LEN=${#TEXT}&lt;BR /&gt;MYVAR="$(print "$TEXT" | cut -c1,$LEN)"&lt;BR /&gt; &lt;BR /&gt;...more script stuff...&lt;BR /&gt;print "First-Last=$MYVAR"&lt;BR /&gt; &lt;BR /&gt;done&lt;BR /&gt; &lt;BR /&gt;The main line is the: MYVAR="$(...)" where the result of the cut command is assigned to a variable called MYVAR. Be sure to use " because there may be a leading and/or trailing space in your file. Then test or use $MYVAR with "$MYVAR" to preserve and special characters.</description>
    <pubDate>Tue, 17 Jun 2008 12:36:45 GMT</pubDate>
    <dc:creator>Bill Hassell</dc:creator>
    <dc:date>2008-06-17T12:36:45Z</dc:date>
    <item>
      <title>Pulling the first and last character/number from a string.</title>
      <link>https://community.hpe.com/t5/operating-system-linux/pulling-the-first-and-last-character-number-from-a-string/m-p/4217417#M91823</link>
      <description>&lt;!--!*#--&gt;Let's say I have a word "foobar23" in a file, and I want to pull the first "f" and last "3" character out of the world, how would I accomplish that?&lt;BR /&gt;&lt;BR /&gt;# cat file&lt;BR /&gt;foobar23&lt;BR /&gt;&lt;BR /&gt;I want the output to be:&lt;BR /&gt;&lt;BR /&gt;f3</description>
      <pubDate>Mon, 16 Jun 2008 22:31:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/pulling-the-first-and-last-character-number-from-a-string/m-p/4217417#M91823</guid>
      <dc:creator>Patrick Ware_1</dc:creator>
      <dc:date>2008-06-16T22:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling the first and last character/number from a string.</title>
      <link>https://community.hpe.com/t5/operating-system-linux/pulling-the-first-and-last-character-number-from-a-string/m-p/4217418#M91824</link>
      <description>Lots of choices depending on the rules. The general way is to use cut as in:&lt;BR /&gt; &lt;BR /&gt;cat file | while read TEXT&lt;BR /&gt;do&lt;BR /&gt;LEN=${#TEXT}&lt;BR /&gt;print $(print "$TEXT" | cut -c1,$LEN)&lt;BR /&gt;done&lt;BR /&gt;</description>
      <pubDate>Mon, 16 Jun 2008 23:13:53 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/pulling-the-first-and-last-character-number-from-a-string/m-p/4217418#M91824</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2008-06-16T23:13:53Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling the first and last character/number from a string.</title>
      <link>https://community.hpe.com/t5/operating-system-linux/pulling-the-first-and-last-character-number-from-a-string/m-p/4217419#M91825</link>
      <description>Thanks!  That worked great!&lt;BR /&gt;Now I am trying to figure out how to make that all a variable that I can embed into a script..</description>
      <pubDate>Tue, 17 Jun 2008 00:07:30 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/pulling-the-first-and-last-character-number-from-a-string/m-p/4217419#M91825</guid>
      <dc:creator>Patrick Ware_1</dc:creator>
      <dc:date>2008-06-17T00:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling the first and last character/number from a string.</title>
      <link>https://community.hpe.com/t5/operating-system-linux/pulling-the-first-and-last-character-number-from-a-string/m-p/4217420#M91826</link>
      <description>&lt;!--!*#--&gt;"man sh".&lt;BR /&gt;&lt;BR /&gt;td192&amp;gt; echo foobar23 | \&lt;BR /&gt; sed -e 's/^\(.\).*\(.\)$/\1\2/'&lt;BR /&gt;f3&lt;BR /&gt;&lt;BR /&gt;td192&amp;gt; x=` echo foobar23 | \&lt;BR /&gt; sed -e 's/^\(.\).*\(.\)$/\1\2/' `&lt;BR /&gt;td192&amp;gt; echo $x&lt;BR /&gt;f3&lt;BR /&gt;&lt;BR /&gt;Or, the trendy, new way:&lt;BR /&gt;&lt;BR /&gt;td192&amp;gt; x=$(echo foobar23 | sed -e 's/^\(.\).*\(.\)$/\1\2/')&lt;BR /&gt;td192&amp;gt; echo $x&lt;BR /&gt;f3&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Jun 2008 01:21:23 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/pulling-the-first-and-last-character-number-from-a-string/m-p/4217420#M91826</guid>
      <dc:creator>Steven Schweda</dc:creator>
      <dc:date>2008-06-17T01:21:23Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling the first and last character/number from a string.</title>
      <link>https://community.hpe.com/t5/operating-system-linux/pulling-the-first-and-last-character-number-from-a-string/m-p/4217421#M91827</link>
      <description>Hi Patrick:&lt;BR /&gt;&lt;BR /&gt;# echo "foobar23"|perl -nle 'print substr($_,0,1),substr($_,-1)'&lt;BR /&gt;f3&lt;BR /&gt;&lt;BR /&gt;# perl -nle 'print substr($_,0,1),substr($_,-1)' file&lt;BR /&gt;f3&lt;BR /&gt;&lt;BR /&gt;...in in your shell script:&lt;BR /&gt;&lt;BR /&gt;# THING=$(perl -nle 'print substr($_,0,1),substr($_,-1)' file)&lt;BR /&gt;# echo ${THING}&lt;BR /&gt;f3&lt;BR /&gt;&lt;BR /&gt;...JRF...&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Jun 2008 09:52:35 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/pulling-the-first-and-last-character-number-from-a-string/m-p/4217421#M91827</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2008-06-17T09:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling the first and last character/number from a string.</title>
      <link>https://community.hpe.com/t5/operating-system-linux/pulling-the-first-and-last-character-number-from-a-string/m-p/4217422#M91828</link>
      <description>&amp;gt; ...variable in the script...&lt;BR /&gt; &lt;BR /&gt;cat file | while read TEXT&lt;BR /&gt;do&lt;BR /&gt;LEN=${#TEXT}&lt;BR /&gt;MYVAR="$(print "$TEXT" | cut -c1,$LEN)"&lt;BR /&gt; &lt;BR /&gt;...more script stuff...&lt;BR /&gt;print "First-Last=$MYVAR"&lt;BR /&gt; &lt;BR /&gt;done&lt;BR /&gt; &lt;BR /&gt;The main line is the: MYVAR="$(...)" where the result of the cut command is assigned to a variable called MYVAR. Be sure to use " because there may be a leading and/or trailing space in your file. Then test or use $MYVAR with "$MYVAR" to preserve and special characters.</description>
      <pubDate>Tue, 17 Jun 2008 12:36:45 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/pulling-the-first-and-last-character-number-from-a-string/m-p/4217422#M91828</guid>
      <dc:creator>Bill Hassell</dc:creator>
      <dc:date>2008-06-17T12:36:45Z</dc:date>
    </item>
    <item>
      <title>Re: Pulling the first and last character/number from a string.</title>
      <link>https://community.hpe.com/t5/operating-system-linux/pulling-the-first-and-last-character-number-from-a-string/m-p/4217423#M91829</link>
      <description>How about this&lt;BR /&gt;&lt;BR /&gt;WORD=`cat filename`&lt;BR /&gt;FIRSTCHAR=`echo $WORD | cut -c 1`&lt;BR /&gt;LASTCHAR=`echo $WORD | rev | cut -c 1`</description>
      <pubDate>Tue, 17 Jun 2008 13:55:29 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/pulling-the-first-and-last-character-number-from-a-string/m-p/4217423#M91829</guid>
      <dc:creator>TTr</dc:creator>
      <dc:date>2008-06-17T13:55:29Z</dc:date>
    </item>
  </channel>
</rss>

