Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2005
    Posts
    3

    Unanswered: awk in script problem

    hi,

    i tried to put this pipe into my .bashrc
    to display my current ip address:

    alias myip="ifconfig | awk '/broadcast / {print $2}'"

    and it prints the full line of the ifconfig output.
    when i test this pipe in the shell like this

    $> ifconfig | awk '/broadcast / {print $2}'

    it works fine.!?

    where is my mistake?

    thank you for the help

    marc

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Try this:
    Code:
    alias myip="ifconfig | awk -v FS=\" \" '/broadcast / {print $2}'"

  3. #3
    Join Date
    Mar 2005
    Posts
    3

    Unhappy still the same

    im sorrry that doesn´t change it.
    i get only the second argument as output when i type it in the shell.
    but in .bashrc i still get the whole line as output.

    how can i get just the second argument as output?
    has it to do with the " or ' s ?

    thank you in advance.

    marc

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    I suspect it has something to do with the default field separator not being set. Can you try and see if this works:

    awk -F" " '/broadcast / {print $2}'

    (Note there is a space between the double quotes).

  5. #5
    Join Date
    Apr 2004
    Location
    Boston, MA
    Posts
    325
    Code:
    alias myip="ifconfig | awk '/broadcast / {print \$2}'"

  6. #6
    Join Date
    Mar 2005
    Posts
    3

    Thumbs up that was it.

    the backslash made it work!
    thank you very much.
    marc

Posting Permissions

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