Find the answer to your Linux question:
Page 2 of 2 FirstFirst 1 2
Results 11 to 20 of 20
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
    947

    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
    12,596
    Code:
    sed -n ${linetoget}p $1.txt
    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
    188
    Rubberman, where would I add that to my script?

  4. $spacer_open
    $spacer_close
  5. #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
    12,596
    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.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  6. #15
    Linux Newbie mactruck's Avatar
    Join Date
    Apr 2012
    Location
    City of Salt
    Posts
    188
    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.

  7. #16
    Linux Newbie mactruck's Avatar
    Join Date
    Apr 2012
    Location
    City of Salt
    Posts
    188
    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
    #

  8. #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
    12,596
    Good work! Glad you got it sorted out. FWIW, I always prefer to teach people how to fish...
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  9. #18
    Linux Newbie mactruck's Avatar
    Join Date
    Apr 2012
    Location
    City of Salt
    Posts
    188
    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.

  10. #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
    12,596
    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!

  11. #20
    Penguin of trust elija's Avatar
    Join Date
    Jul 2004
    Location
    Either at home or at work or down the pub
    Posts
    3,842
    Never mind. Beaten to it by 18 hours!
    Should you be sitting wondering,
    Which Batman is the best,
    There's only one true answer my friend,
    It's Adam Bloody West!


    The Fifth Continent

Posting Permissions

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