Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!uunet!stanford.edu!snorkelwacker.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!jik From: jik@athena.mit.edu (Jonathan I. Kamens) Newsgroups: comp.unix.questions Subject: Re: Variables in csh Message-ID: <1991May2.165922.10558@athena.mit.edu> Date: 2 May 91 16:59:22 GMT References: <9105020702.AA06707@csufres.CSUFresno.EDU> Sender: news@athena.mit.edu (News system) Organization: Massachusetts Institute of Technology Lines: 46 In article <9105020702.AA06707@csufres.CSUFresno.EDU>, quang@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@Athena.MIT.EDU Allston, MA 02134 Office: 617-253-8085 Home: 617-782-0710