Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2005
    Posts
    26

    Unanswered: Read each line of a file

    Hi all,

    If I have a file that looks like this:

    dallas
    new york
    chicago
    los angeles

    In a unix script how I can grab one line at a time in that file and email it to someone?

  2. #2
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    Check the man pages for read, while and mailx

    cat <filename> | while read fileline
    do
    echo $fileline | mailx ....
    done

  3. #3
    Join Date
    Feb 2005
    Posts
    2

    another method

    for i in `cat <filename>`
    do
    mail -s "Your monthly sales figures" $i
    done

    It's been awhile since I've used the mail utility and you may use something different so that line may need tweaking.

    I use the 'for/cat' combination all the time and this is how I would do what I think it is that you're asking.

  4. #4
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    Quote Originally Posted by dbrooker
    I use the 'for/cat' combination
    That will read one word at a time, not one line at a time
    Code:
    for i in `cat file1`
    do
      echo ">>>$i<<<"
    done
    >>>dallas<<<
    >>>new<<<
    >>>york<<<
    >>>chicago<<<
    >>>los<<<
    >>>angeles<<<

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •