LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-17-2007, 06:10 PM   #1
isra
Member
 
Registered: Jan 2006
Location: Mexico, city
Distribution: DEBIAN, OpenSolaris
Posts: 32

Rep: Reputation: 15
Output of the ifconfig command


How can i add an ip address and mac adderess of the ifconfig command to a file?
I konow that awk solves the problem but how.
my archive is /tmp/armd
somebody told me to use sth like this:
awk -vval=$( ifconfig eth0 | grep "inet addr" | cut -d" " -f1 ) 'BEGIN{v2=val} { if (NR==1) {print $0" "v2} else print; }' /tmp/armd
what i want is this:
i have this archive /tmp/armd:
asdmpo sdmpm pnsad
pomsd osndsd snsdoni
and what i need is this:
asdmpo sdmpm pnsad 192.168.100.1 00:09:6B:5F:4EB
pomsd osndsd snsdoni 192.168.100.1 00:09:6B:5F:4EB

Last edited by isra; 03-17-2007 at 07:37 PM.
 
Old 03-17-2007, 07:52 PM   #2
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Just use a redirect to put the output into a file..

command > file
 
Old 03-18-2007, 01:47 PM   #3
isra
Member
 
Registered: Jan 2006
Location: Mexico, city
Distribution: DEBIAN, OpenSolaris
Posts: 32

Original Poster
Rep: Reputation: 15
but my file would be this

asdmpo sdmpm pnsad
pomsd osndsd snsdoni
192.168.100.1
00:09:6B:5F:4EB
192.168.100.1
00:09:6B:5F:4EB
using command >> file
 
Old 03-19-2007, 11:09 AM   #4
trickykid
LQ Guru
 
Registered: Jan 2001
Posts: 24,149

Rep: Reputation: 269Reputation: 269Reputation: 269
Oh I see.. you might be able to use the column command, not sure, never really used it myself or you could craft up a perl script to manipulate the data in the order that you desire.
 
Old 03-19-2007, 11:34 AM   #5
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
That's awfull in one line but.. here we go:
Code:
awk -vval="`/sbin/ifconfig eth0 | awk '/inet/ {print $2} /HWaddr/ {printf $5} ' | sed 's/adr:/ /' `" '{printf $0" "; print val}' /tmp/armd
 
Old 03-20-2007, 10:24 AM   #6
isra
Member
 
Registered: Jan 2006
Location: Mexico, city
Distribution: DEBIAN, OpenSolaris
Posts: 32

Original Poster
Rep: Reputation: 15
oh,oohh, that's awesome, i'll probe it.
Thanks

Last edited by isra; 03-20-2007 at 10:25 AM.
 
Old 03-20-2007, 10:46 AM   #7
isra
Member
 
Registered: Jan 2006
Location: Mexico, city
Distribution: DEBIAN, OpenSolaris
Posts: 32

Original Poster
Rep: Reputation: 15
i want to lern more about it. How can i delete addr: an put a blank " ". This is the output:
# awk -vval="`/sbin/ifconfig eth0 | awk '/inet/ {print $2} /HWaddr/ {printf $5} ' | sed 's/adr:/ /' `" '{printf $0" "; print val}' /tmp/armd5

4a2fd01b461f892c972fec9e41ea5d33 /tmp//bin.tar 08:00:46:EE:86:ACaddr:192.168.245.95
c61153a9d34c1d84c9cd11b7072c952b /tmp//etc.tar 08:00:46:EE:86:ACaddr:192.168.245.95
20340618f9ed1613c2de0bd322f64966 /tmp//sbin.tar 08:00:46:EE:86:ACaddr:192.168.245.95
70e4d1a2b16c5f1ec4d1c0abfecb26f9 /tmp/ubin.tar 08:00:46:EE:86:ACaddr:192.168.245.95
45cbc69a05f9ba371534e2e6a181404a /tmp/subin.tar 08:00:46:EE:86:ACaddr:192.168.245.95

and delete /tmp/, .tar.
 
Old 03-20-2007, 10:49 AM   #8
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
Okay on your system it's addr, on mine adr (in french)

Code:
sed 's/adr:/ /'
This replaces adr: by a space

You need to change adr to addr



awk -vval="`/sbin/ifconfig eth0 | awk '/inet/ {print $2} /HWaddr/ {printf $5} ' | sed 's/addr:/ /' `" '{printf $0" "; print val}' /tmp/armd5

http://sed.sourceforge.net/
 
Old 03-20-2007, 11:13 AM   #9
isra
Member
 
Registered: Jan 2006
Location: Mexico, city
Distribution: DEBIAN, OpenSolaris
Posts: 32

Original Poster
Rep: Reputation: 15

As we say in spanish:
"Que rifado!!"
 
  


Reply



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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ifconfig output : unknown device dark* Slackware 15 09-03-2006 11:04 PM
connecting /sbin/ifconfig to bash command ifconfig flammable2 Fedora 4 11-12-2005 07:58 AM
display ifconfig output in php ?? ALInux Programming 1 10-29-2005 04:23 PM
ifconfig output alaios Linux - Networking 8 12-02-2004 02:40 AM
ifconfig command shoot2kill Linux - Networking 10 10-22-2003 12:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration