• Home
  • About
  • Map
  • Archives
  • Videos
  • Gallery
Grab the RSS feed

spiralbound.net

spiralbound.net
  • Home
  • Adventures
  • Data and Technology
  • Et cetera
  • Highlights

Foreach Example in tcsh

  • Data and Technology

    Posted on January 17th, 2006

    Written by cliff

    Related Posts

    • RHEL useradd Syntax
    • Bash For loop Example
    • Using Sort to List Directories by Size

    Tags

    foreach, grep, ls, shell, syntax, tcsh

    I always forget the foreach syntax. Here is a quick example that reads all the contents of a directory into an array, prints out the name of each file, runs a simple grep on it, and ends.

    foreach i ( ` /bin/ls * ` )
    foreach? echo $i
    foreach?/bin/grep your_grep_string $i
    foreach? end

    This entry was posted on Tuesday, January 17th, 2006 at 10:51 am and is filed under Data and Technology. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
  • 6 Comments

    Take a look at some of the responses we have had to this article.

    1. spiralbound.net » Using Sort to List Directories by Size
      Nov 27th
      Reply

      [...] If you have nested directories, you will need to incorporate foreach to recurse through and get all the directory names. [...]

    2. Anuj Arora
      Jun 8th
      Reply

      gr8 link, help a lot, thanks….

    3. spiralbound.net » Bash For loop Example
      Jul 23rd
      Reply

      [...] forgetting the syntax to make “for” loops in Bash. I guess it serves me right for using foreach most of my UNIX life instead. Anyhow, I know I will have to come back here to find it, so I thought [...]

    4. Dennis
      Nov 12th
      Reply

      Thanks a lot, men!

    5. naga
      Sep 8th
      Reply

      How I can write loop without nubmers but with some strings like ‘a’, ‘b’, ‘c’?

    6. Brian
      Mar 3rd
      Reply

      Thanks for the info! Very simple. Helps a lot

  • Leave a Reply

    Let us know what you thought. Click here to cancel reply.

  • Name(required):

    Email(required):

    Website:

    Message:

  • Sponsor
  • Recent Comments
    • fabioamd87 on IFCONFIG Does Not give You Link Status; ETHTOOL Does
    • Komil on Quick Start Guide for Asterisk
    • cheap tiffany s jewelry and mont blanc pens on German Kite Skates Across Australia
    • Kim on Giant Rabbits in North Korea
    • Emad on Little Japanese Trucks
    • Jonathan on Why Did my Arm Fall Asleep?
    • Jenn on 802 – Hip Hop Vermont Style

Copyright © 2010 spiralbound.net - Powered by Wordpress