If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > awk in script problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-08-05, 16:39
go4 go4 is offline
Registered User
 
Join Date: Mar 2005
Posts: 3
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
Reply With Quote
  #2 (permalink)  
Old 03-08-05, 20:49
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,454
Try this:
Code:
alias myip="ifconfig | awk -v FS=\" \" '/broadcast / {print $2}'"
Reply With Quote
  #3 (permalink)  
Old 03-09-05, 03:09
go4 go4 is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 03-09-05, 09:17
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,454
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).
Reply With Quote
  #5 (permalink)  
Old 03-09-05, 10:16
vgersh99 vgersh99 is offline
Registered User
 
Join Date: Apr 2004
Location: Boston, MA
Posts: 325
Code:
alias myip="ifconfig | awk '/broadcast / {print \$2}'"
Reply With Quote
  #6 (permalink)  
Old 03-09-05, 18:21
go4 go4 is offline
Registered User
 
Join Date: Mar 2005
Posts: 3
Thumbs up that was it.

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On