Search Options
close
Search the following clips:
All Clips
Everyone's Clips
My Guides
Sign Up
Install
Learn More
Login
Bash script string indexing
lizponine
follow
0
9-15-2009 2:10 PM
167 views
tags:
bash
,
script
,
string
lizponine
says:
reminder how to index strings in bash scripts
Add a Comment
Login
to Comment. Not a member yet?
Sign up
Today's Top Clips
The Truth About Work
house that can rotate to follow the sun
video: The Moscow Cat Circus
Ocean's Most Colorful Slugs
COURAGE.... WE SHARE IT.
Gibralter Airport
The Greatest Secrets of Mankind
how a man lost 300 lbs - bicycling
stunning images shot for an underwater film
Remembrance day conman named and shamed
visit the
Top Clips page
View the Top Clips from
September 15, 2009
Embed This Clip In Your Site...
<div style="margin: 12px 0px; font-family: arial; color: #333333; background: #ffffff; border: solid 4px #e5e5e5; width: 100%; clear: left;"><div class="CM_CTB_Content_Wrap" style="margin: 0px; padding: 0px;background-color: #ffffff;"><div style="border-bottom: solid 1px #dcdcdc; white-space: nowrap; margin-bottom: 8px; background-color: #eeeeee ;background-image: url(http://clipmarks.com/images/source-bg.gif); background-repeat: repeat-x; height: 24px; line-height: 24px; vertical-align: middle; padding-bottom: 4px; color: #666666; font-size: 10px;" ><a href="http://clipmarks.com/clip-to-blog/" title="see clips that are hot right now"><img src="http://content.clipmarks.com/blog_embed/1dac10fd-0125-4edb-a1b7-c3ba7602ec57/C5088D8A-9A0A-4851-AB15-0A8131B24CBE/" alt="" width="19" height="19" border="0" style="vertical-align: middle; margin: 0px 4px; display: inline; border: none; float:none;" /></a>clipped from <a title="http://www.faqs.org/docs/abs/HTML/string-manipulation.html" href="http://www.faqs.org/docs/abs/HTML/string-manipulation.html" style="font-size: 11px;">www.faqs.org</a></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://www.faqs.org/docs/abs/HTML/string-manipulation.html"><B>Index</B></blockquote><div style="height: 2px; font-size: 2px; background: #dcdcdc; border-bottom: solid 1px #f5f5f5; margin: 2px 4px;"></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://www.faqs.org/docs/abs/HTML/string-manipulation.html"><DT>expr index $string $substring</DT></blockquote><div style="height: 2px; font-size: 2px; background: #dcdcdc; border-bottom: solid 1px #f5f5f5; margin: 2px 4px;"></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://www.faqs.org/docs/abs/HTML/string-manipulation.html"><P>Numerical position in $string of first character in $substring that matches.</P></blockquote><div style="height: 2px; font-size: 2px; background: #dcdcdc; border-bottom: solid 1px #f5f5f5; margin: 2px 4px;"></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://www.faqs.org/docs/abs/HTML/string-manipulation.html"><PRE class="PROGRAMLISTING"> 1 stringZ=abcABC123ABCabc 2 echo `expr index "$stringZ" C12` # 6 3 # C position. 4 5 echo `expr index "$stringZ" 1c` # 3 6 # 'c' (in #3 position) matches before '1'.</PRE></blockquote><div style="height: 2px; font-size: 2px; background: #dcdcdc; border-bottom: solid 1px #f5f5f5; margin: 2px 4px;"></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://www.faqs.org/docs/abs/HTML/string-manipulation.html"><B>Substring Extraction</B></blockquote><div style="height: 2px; font-size: 2px; background: #dcdcdc; border-bottom: solid 1px #f5f5f5; margin: 2px 4px;"></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://www.faqs.org/docs/abs/HTML/string-manipulation.html"><DT>${string:position}</DT></blockquote><div style="height: 2px; font-size: 2px; background: #dcdcdc; border-bottom: solid 1px #f5f5f5; margin: 2px 4px;"></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://www.faqs.org/docs/abs/HTML/string-manipulation.html"><P>Extracts substring from <TT class="REPLACEABLE"><I>$string</I></TT> at <TT class="REPLACEABLE"><I>$position</I></TT>.</P></blockquote><div style="height: 2px; font-size: 2px; background: #dcdcdc; border-bottom: solid 1px #f5f5f5; margin: 2px 4px;"></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://www.faqs.org/docs/abs/HTML/string-manipulation.html"><DT>${string:position:length}</DT></blockquote><div style="height: 2px; font-size: 2px; background: #dcdcdc; border-bottom: solid 1px #f5f5f5; margin: 2px 4px;"></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://www.faqs.org/docs/abs/HTML/string-manipulation.html"><P>Extracts <TT class="REPLACEABLE"><I>$length</I></TT> characters of substring from <TT class="REPLACEABLE"><I>$string</I></TT> at <TT class="REPLACEABLE"><I>$position</I></TT>.</P></blockquote><div style="height: 2px; font-size: 2px; background: #dcdcdc; border-bottom: solid 1px #f5f5f5; margin: 2px 4px;"></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://www.faqs.org/docs/abs/HTML/string-manipulation.html"><PRE class="PROGRAMLISTING"> 1 stringZ=abcABC123ABCabc 2 # 0123456789..... 3 # 0-based indexing. 4 5 echo ${stringZ:0} # abcABC123ABCabc 6 echo ${stringZ:1} # bcABC123ABCabc 7 echo ${stringZ:7} # 23ABCabc 8 9 echo ${stringZ:7:3} # 23A 10 # Three characters of substring.</PRE></blockquote><div style="height: 2px; font-size: 2px; background: #dcdcdc; border-bottom: solid 1px #f5f5f5; margin: 2px 4px;"></div><blockquote style="text-align: left; padding: 0px 8px; margin: 4px 0px 8px 0px; background: transparent; border: none;" cite="http://www.faqs.org/docs/abs/HTML/string-manipulation.html"><P>This is the near equivalent of <SPAN class="emphasis"><I class="EMPHASIS">strchr()</I></SPAN> in C.</P></blockquote></div><div style="margin: 0px 6px 6px 4px;"><table style="font-size: 11px;border-spacing: 0px;padding: 0px;" cellpadding="0" cellspacing="0" width="100%"><tr><td style="background:transparent;border-width:0px;padding:0px;"> </td><td align="right" style="background:transparent;border-width:0px;padding:0px;width:107px" width="107"><a href="http://clipmarks.com/share/C5088D8A-9A0A-4851-AB15-0A8131B24CBE/blog/" title="blog or email this clip"><img src="http://content7.clipmarks.com/images/c2b-foot.png" border="0" alt="blog it" width="107" height="17" style="border-width:0px;padding:0px;margin:0px;" /></a></td></tr></table></div></div>
New from the makers of Clipmarks:
Amplify.com - Don't just share the news...Amplify it!
Clipmarks
Home
New Clips
Top Clips
Dashboard
Popular Topics
News
Life
Science
Technology
Entertainment
Get Started
Sign Up
Install Clipping Tool
How Clipping Works
Clip-to-Blog™
ClipSearch
Tools and Resources
FAQ
ClipWeek
Top Clippers
Top Tags
Site Map
About Clipmarks
About Us
Contact
Copyright
Privacy
EULA
OK