Variables in csh
Jonathan I. Kamens
jik at athena.mit.edu
Fri May 3 02:59:22 AEST 1991
In article <9105020702.AA06707 at csufres.CSUFresno.EDU>, quang at CSUFRES.CSUFRESNO.EDU (Quang Ngo) writes:
|> 1) [how to take substrings in csh]
Csh has no facility for doing substrings. You need to use something like awk
or expr. Given your example:
|> Now, let's say I have
|>
|> set a = "This is a string"
|>
|> How do I print 'str' ?
You could do something like this:
echo "$a" | awk '{print substr($0, 11, 3)}'
|> 2) [How to keep spaces from being record separators in a data file read
|> into a foreach loop using backquote substitution and "cat"]
Enclose the backquote substitution in double quotes. For example, given your
data file:
|> John 234
|> Bill 123
|> Tom 231
And this script:
#!/bin/csh -f
foreach a ("`cat data`")
echo $a
end
(which differs from yours only in the addition of backquotes), the following
output results:
John 234
Bill 123
Tom 231
--
Jonathan Kamens USnail:
MIT Project Athena 11 Ashford Terrace
jik at Athena.MIT.EDU Allston, MA 02134
Office: 617-253-8085 Home: 617-782-0710
More information about the Comp.unix.questions
mailing list