In a message dated: Tue, 27 Mar 2001 09:54:06 EST
"Mansur, Warren" said:

>Hi,
>
>I'm on a box that uses csh as its default shell, so I'm wondering if there
>is a way in csh shell scripting to read in a file a line at a time, and then
>get the fourth token on each line.

Are you trying to write a self-contained shell script program?  If 
so, the default shell (used for command line/login) has nothing to do 
with what your write your shell script in.

If this is the case, then I highly recommend using perl for this type 
of problem.

>The tokens are separated by spaces, such as:
>
>token1 token2 token3 token4 token5 . . .
>
>And the file contains many lines.  Does anyone know how to do this?

In any shell from the command line:

        $ awk '{print $4}'

will spew forth the 4th token from each line.  If white space is not the 
delimiter between tokens, use -F<delimiter> to force a different delimiter.
For example, to grab the 4th field of the password file:

        $ awk -F: '{print $4}'

Of course, you can do the same with perl:

        $ perl -ane  'print "$F[3]\n";'

Or with other utilities:

        $ cut -f4 -d' ' file.txt

You can probably use col or pr for this as well, but you'd have to 
read the man pages.

In general though, this really isn't a shell-specific problem.

Hope that helps.

          

        
-- 

Seeya,
Paul
----
        It may look like I'm just sitting here doing nothing,
   but I'm really actively waiting for all my problems to go away.

         If you're not having fun, you're not doing it right!



**********************************************************
To unsubscribe from this list, send mail to
[EMAIL PROTECTED] with the following text in the
*body* (*not* the subject line) of the letter:
unsubscribe gnhlug
**********************************************************

Reply via email to