![]() |
|
|||||||
| Programming C, bash, Python, Perl, PHP, Java, you name it. |
![]() |
|
|
Thread Tools | Display Modes |
|
|||
|
See the expr(1) man page
Code:
$ text=ThisIsMyDumbTextLine $ expr $text : '\(.....\)' ThisI $ expr $text : '.*\(.....\)$' tLine $ expr $text : '.*' 20 Code:
$ text='1234567890'
$ expr $text : '.\{4\}\(.\{5\}\)'
56789.
__________________
You don't need to be a genius to debug a pf.conf firewall ruleset, you just need the guts to run tcpdump Last edited by J65nko; 4th September 2008 at 10:19 PM. Reason: Midstring equivalent added |
|
||||
|
Quote:
Quote:
__________________
religions, worst damnation of mankind "If 386BSD had been available when I started on Linux, Linux would probably never had happened." Linus Torvalds Linux is not UNIX! Face it! It is not an insult. It is fact: GNU is a recursive acronym for “GNU's Not UNIX”. vermaden's: links resources deviantart spreadbsd |
|
||||
|
This is one of my favorite (g)awk references: http://www.gnu.org/software/gawk/man...ode/index.html
See String Manipulation Functions.
__________________
Kill your t.v. |
|
||||
|
You can also use head and tail with the -c switch.
__________________
UNIX was not designed to stop you from doing stupid things, because that would also stop you from doing clever things. |
|
||||
|
Hi.
Some shells have this built-in for variables: Code:
#!/bin/bash -
# @(#) s1 Demonstrate bash substring expansion.
echo
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version "=o" $(_eat $0 $1)
set -o nounset
echo
echo " Results:"
t="0123456789abcdefghij"
echo
echo $t
echo
i=0
echo " First 5 ${t:$i:5}"
echo
i=-5
echo " Last 5 ${t:$i:5}"
echo
i=3
echo " 3 from 4 ${t:$i:3}"
exit 0
Code:
% ./s1 (Versions displayed with local utility "version") Linux 2.6.11-x1 GNU bash 2.05b.0 Results: 0123456789abcdefghij First 5 01234 Last 5 fghij 3 from 4 345 |
|
||||
|
A thousand and one different ways, one thing you might consider is, how easy can you remember it; without having to pick apart the script later when you haven't looked at it in the last 9 months.
__________________
My Journal Thou shalt check the array bounds of all strings (indeed, all arrays), for surely where thou typest ``foo'' someone someday shall type ``supercalifragilisticexpialidocious''. |
![]() |
| Tags |
| awk, cut, expr, string manipulation, substring |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| command-line-fu (digg like site with UNIX commands) | vermaden | Guides | 3 | 13th March 2009 02:56 PM |
| avidemux2 command line | roddierod | FreeBSD General | 1 | 10th November 2008 07:27 PM |
| OSS , playing a sound via command line.. | scotsman | FreeBSD General | 7 | 29th August 2008 08:01 PM |
| TCSH - getting to start of line | maxrussell | FreeBSD General | 3 | 4th July 2008 11:55 AM |
| Trouble burning to dvdrw part 2 | whispersGhost | Solaris | 32 | 3rd June 2008 12:51 PM |