next up previous 405
Next: String concatenation
Up: C-shell Cookbook
Previous: Intrinsic Functions


String Processing

The C-shell has no string-manipulation tools. Instead we mostly use the echo command and awk utility. The latter has its own language for text processing and you can write awk scripts to perform complex processing, normally from files. There are even books devoted to awk such as the succinctly titled sed & awk by Dale Dougherty (O'Reilly & Associates, 1990). Naturally enough a detailed description is far beyond the scope of this cookbook.

Other relevant tools include cut, paste, grep and sed. The last two and awk gain much of their power from regular expressions. A regular expression is a pattern of characters used to match the same characters in a search through text. The pattern can include special characters to refine the search. They include ones to anchor to the beginning or end of a line, select a specific number of characters, specify any characters and so on. If you are going to write lots of scripts which manipulate text, learning about regular expressions is time well spent.

Here we present a few one-line recipes. They can be included inline, but for clarity the values derived via awk are assigned to variables using the set command. Note that these may not be the most concise way of achieving the desired results.


Subsections

next up previous 405
Next: String concatenation
Up: C-shell Cookbook
Previous: Intrinsic Functions

C-shell Cookbook
Starlink Cookbook 4
Malcolm J. Currie
2006 November 26
E-mail:starlink@jiscmail.ac.uk

Copyright © 2013 Science and Technology Facilities Council