정규표현식을 이용해서 # ifconfig eth0 정보중 IP만 얻을수 있

익명 사용자의 이미지

정규표현식을 이용하여 ifconfig eth0중에서 ip만 얻고 싶습니다.
sed를 사용해봤는데, ip줄 모두가 출력 됩니다.
# ifconfig eth0 | sed -n -e 's/.*addr\(.*\)/\1/p'
192.168.1.1 Bcast192.168.1.255 Mask255.255.255.0

그리고 나중엔 Bcase만 얻고, Mask만 얻기를 원합니다.
어떻게 하면 되는지요??

# ifconfig eth0
eth0 Link encapEthernet HWaddr 00C026F00B4E
inet addr192.168.1.1 Bcast192.168.1.255
mask255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU1500 Metric1
RX packets46682 errors0 dropped0 overruns0 frame0
TX packets15767 errors0 dropped0 overruns0 carrier0
collisions39 txqueuelen100
Interrupt11 Base address0xec00

익명 사용자의 이미지

ifconfig eth0 | sed -n -e 's/.*addr\([^ ]*\).*Bcast\([^ ]
*\).*Mask\([^ ]*\)/\1/p'

ifconfig eth0 | sed -n -e 's/.*addr\([^ ]*\).*Bcast\([^ ]
*\).*Mask\([^ ]*\)/\2/p'

ifconfig eth0 | sed -n -e 's/.*addr\([^ ]*\).*Bcast\([^ ]
*\).*Mask\([^ ]*\)/\3/p'

이런식으로 해보세요.

다른 방법은 저두 잘 모르겠네요....^^

익명 사용자의 이미지

윗 분이 답장을 했지만, 다른 방법도 있어서 추가로 답장을 합니다.

님이 사용한
# ifconfig eth0 | sed -n -e 's/.*addr\(.*\)/\1/p' 다음에 pipe와 awk를 사용하면
됩니다.

만약,
Bcast192.168.1.255 뽑아 내길 원한다면,

# ifconfig eth0 | sed -n -e 's/.*addr\(.*\)/\1/p' | awk '{print $2}'

입니다.

만약에 Bcase의 192.168.1.255 만 뽑아 내길 원한다면,

ifconfig eth0 | sed -n -e 's/.*addr\(.*\)/\1/p' | awk '{print $2}' | awk --field-separator '{print $2}'

라고 하면되는데요, 더 간단한 방법이 있을 것 같습니다..

참고만 하세요.
----------------
정규표현식을 이용하여 ifconfig eth0중에서 ip만 얻고 싶습니다.
sed를 사용해봤는데, ip줄 모두가 출력 됩니다.
# ifconfig eth0 | sed -n -e 's/.*addr\(.*\)/\1/p'
192.168.1.1 Bcast192.168.1.255 Mask255.255.255.0

그리고 나중엔 Bcase만 얻고, Mask만 얻기를 원합니다.
어떻게 하면 되는지요??

# ifconfig eth0
eth0 Link encapEthernet HWaddr 00C026F00B4E
inet addr192.168.1.1 Bcast192.168.1.255
mask255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU1500 Metric1
RX packets46682 errors0 dropped0 overruns0 frame0
TX packets15767 errors0 dropped0 overruns0 carrier0
collisions39 txqueuelen100
Interrupt11 Base address0xec00

익명 사용자의 이미지

두분다 감사합니다.
저는 아무리 봐도 정규식을 이해하지 못하겠던데.....

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.