~ubuntu-branches/ubuntu/natty/abs-guide/natty

« back to all changes in this revision

Viewing changes to abs/substring-extraction.sh

  • Committer: Bazaar Package Importer
  • Author(s): Sandro Tosi
  • Date: 2010-05-09 17:49:52 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20100509174952-1s583w0zbh7rl1po
Tags: 6.2-1
* New upstream release; Closes: #441278
* debian/control
  - adopting package; Closes: #577181
  - removed bzip2 from b-d-i, no more needed
  - debhelper has to be in b-d
  - bump Standards-Version to 3.8.4 (no changes needed)
  - added Homepage field
  - added misc:Depends to Depends
  - added Vcs-{Browser, Git} field
* debian/rules
  - removed the unpacking stuff, we now use an alrqady unpacked source
  - added more example scripts to fix
* debian/{compat, control, rules}
  - switched to debhelper 7
* debian/watch
  - updated to new upstream location; thanks to Raphael Geissert for the
    report; Closes: #453596
* debian/copyright
  - updated with new location and copyright/license notices
* debian/source/format
  - set source package format to 1.0 explicitly
* debian/abs-guide.doc-base
  - set Section field correctly
* debian/{copyright, abs-guide.doc-base}
  - updated upstream email
* debian/abs-guide.lintian-overrides
  - added override for "known syntax-errored" scripts

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
# substring-extraction.sh
 
3
 
 
4
String=23skidoo1
 
5
#      012345678    Bash
 
6
#      123456789    awk
 
7
# Note different string indexing system:
 
8
# Bash numbers first character of string as 0.
 
9
# Awk  numbers first character of string as 1.
 
10
 
 
11
echo ${String:2:4} # position 3 (0-1-2), 4 characters long
 
12
                                         # skid
 
13
 
 
14
# The awk equivalent of ${string:pos:length} is substr(string,pos,length).
 
15
echo | awk '
 
16
{ print substr("'"${String}"'",3,4)      # skid
 
17
}
 
18
'
 
19
#  Piping an empty "echo" to awk gives it dummy input,
 
20
#+ and thus makes it unnecessary to supply a filename.
 
21
 
 
22
echo "----"
 
23
 
 
24
# And likewise:
 
25
 
 
26
echo | awk '
 
27
{ print index("'"${String}"'", "skid")      # 3
 
28
}                                           # (skid starts at position 3)
 
29
'   # The awk equivalent of "expr index" ...
 
30
 
 
31
exit 0