Find the answer to your Linux question:
Page 2 of 2 FirstFirst 1 2
Results 11 to 20 of 20
Like Tree9Likes
A simple and inelegant way would be to do something like head -n$linetoget | tail -n1...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #11
    Linux Engineer
    Join Date
    Apr 2012
    Location
    Virginia, USA
    Posts
    896

    A simple and inelegant way would be to do something like
    head -n$linetoget | tail -n1

  2. #12
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,601
    Code:
    sed -n ${linetoget}p $1.txt
    mactruck likes this.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #13
    Linux Newbie mactruck's Avatar
    Join Date
    Apr 2012
    Location
    City of Salt
    Posts
    187
    Rubberman, where would I add that to my script?

  4. #14
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,601
    Quote Originally Posted by mactruck View Post
    Rubberman, where would I add that to my script?
    Where do you think you should add it? Make a try - adapt the code to suit - and I'll be happy to critique / correct your effort.
    mactruck likes this.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  5. #15
    Linux Newbie mactruck's Avatar
    Join Date
    Apr 2012
    Location
    City of Salt
    Posts
    187
    Oh My.... I am so close. I have it displaying a random message now, just not in the subject line. I should have it real soon.

  6. #16
    Linux Newbie mactruck's Avatar
    Join Date
    Apr 2012
    Location
    City of Salt
    Posts
    187
    Thanks for all of your help. It took a while but it works like a charm.

    Code:
    #!/usr/bin/bash
    #
    #set -x
    #
    
    numberoflines=`cat /notp/MIKE/scripts/subject.email | wc -l`
    linetoget=$[ ( $RANDOM % $numberoflines ) ]
    mike=`sed -n ${linetoget}p /notp/MIKE/scripts/subject.email`
    
    uuencode $1 $1.txt | mail -s "$mike" mactruck@home.com
    
    #
    #END
    #

  7. #17
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,601
    Good work! Glad you got it sorted out. FWIW, I always prefer to teach people how to fish...
    mactruck likes this.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  8. #18
    Linux Newbie mactruck's Avatar
    Join Date
    Apr 2012
    Location
    City of Salt
    Posts
    187
    ok... I hope this is the last question. Now some times when it does the random number it picks "0" and since that is not a line it has nothing to add to the subject line. I ran the script with set -x and verified this. Is there a way to exclude line 0?

    Here is line 0 (bad)
    Code:
    ++ cat /notp/MIKE/scripts/subject.email
    ++ wc -l
    + numberoflines='       5'
    + linetoget=0
    ++ sed -n 0p /notp/MIKE/scripts/subject.email
    + mike=
    + echo
    
    + uuencode file.20130310 file.20130310.txt
    + mail -s '' mactruck@home.com
    Here is line 4 (good)
    Code:
    ++ cat /notp/MIKE/scripts/subject.email
    ++ wc -l
    + numberoflines='       5'
    + linetoget=4
    ++ sed -n 4p /notp/MIKE/scripts/subject.email
    + mike='I hope this helps.'
    + echo I hope this helps.
    I hope this helps.
    + uuencode file.20130310 file.20130310.txt
    + mail -s 'I hope this helps.' mactruck@home.com
    Again thanks for all of your help and making me think and not just giving me the answer.

  9. #19
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,601
    Simple solution? Add one to the result, since if your file has N lines, your code returns 0 to N-1...
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  10. #20
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    3,571
    Never mind. Beaten to it by 18 hours!
    What do we want?
    Time machines!

    When do we want 'em?
    Doesn't really matter does it!?


    The Fifth Continent

Page 2 of 2 FirstFirst 1 2

Posting Permissions

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