Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 18
I'm having problems with the newline character on the end of a variable. The variable is storing an ip address assigned like this: ... | awk '{print $NF}' | uniq ...
  1. #1
    Ezo
    Ezo is offline
    Just Joined!
    Join Date
    Dec 2007
    Posts
    10

    Question Scripting, removing newline

    I'm having problems with the newline character on the end of a variable.

    The variable is storing an ip address assigned like this:

    ... | awk '{print $NF}' | uniq | while read LINE

    when I attempt to look up information with host I get this:

    host $LINE
    Which returns - Host 190.126.210.135\013 not found: 3(NXDOMAIN)

    I'm been playing with awk and sed to get rid of the newline but I've had no luck and would welcome some help.

    Thanks

  2. #2
    Linux User
    Join Date
    Aug 2006
    Posts
    458
    show the whole thing

  3. #3
    Ezo
    Ezo is offline
    Just Joined!
    Join Date
    Dec 2007
    Posts
    10
    input=../files/data*

    tac $input | grep "string" | awk '{print $NF}' | uniq | while read LINE
    do
    host $LINE
    done

  4. #4
    Linux Engineer wje_lf's Avatar
    Join Date
    Sep 2007
    Location
    Mariposa
    Posts
    1,192
    That's not a newline you're struggling with. The newline has already been removed for you. You seem to have a CR before the LF.

    Try this:
    Code:
    tac $input | fromdos | grep "string" | awk '{print $NF}' | uniq | while read LINE
    do
    host $LINE
    done
    For more information, do this at the command line:
    Code:
    man fromdos
    Hope this helps.
    --
    Bill

    Old age and treachery will overcome youth and skill.

  5. #5
    Ezo
    Ezo is offline
    Just Joined!
    Join Date
    Dec 2007
    Posts
    10
    Sorry I should have said I'm using Bash, it doesn't appear to support that command.

  6. #6
    Just Joined!
    Join Date
    Nov 2004
    Posts
    18
    you can try

    Code:
    tac $input | grep "string" | awk '{print $NF}' | uniq | tr -d '\v' | while read LINE
    do
    host "$LINE"
    done

  7. #7
    Ezo
    Ezo is offline
    Just Joined!
    Join Date
    Dec 2007
    Posts
    10
    That hasn't worked, output is the same.

  8. #8
    Just Joined!
    Join Date
    Nov 2004
    Posts
    18
    well, the next thing would be:
    Code:
    tac $input | grep "string" | awk '{print $NF}' | uniq | tr -d '\013' | while read LINE
    do
    host "$LINE"
    done

  9. #9
    Ezo
    Ezo is offline
    Just Joined!
    Join Date
    Dec 2007
    Posts
    10
    I did try that as well, no luck.

  10. #10
    Just Joined!
    Join Date
    Nov 2004
    Posts
    18
    How about:
    Code:
    for h in "$(tac $input | grep "string" | awk '{print $NF}' | uniq)"; do
        host "$h"
    done

Page 1 of 2 1 2 LastLast

Posting Permissions

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