LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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
 
LinkBack Search this Thread
Old 02-06-2006, 04:20 AM   #1
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 660
Blog Entries: 6

Rep: Reputation: 31
display only first line in "cut"


Hi

I wana get the dns IP from /cat/resolv.conf
Here is my code
cat /etc/resolv.conf | cut -d" " -f2
But I get
my first DNS
the second DNS

I only want the first line displayed...please

Bye
 
Old 02-06-2006, 05:08 AM   #2
guedellas
Member
 
Registered: Dec 2005
Location: Espaņa
Distribution: Fedora Core 8 + Debian 4.0 + Vista
Posts: 61

Rep: Reputation: 15
try
head -n1 /etc/resolv.conf | cut -d" " -f2

instead of cat
 
Old 02-06-2006, 08:06 AM   #3
homey
Senior Member
 
Registered: Oct 2003
Posts: 3,057

Rep: Reputation: 53
It may be a job for sed in this case because, my /etc/resolv.conf has two lines before the actual dns addresses.
Head -n3 /etc/resolv.conf will also print those first two lines.

For example: I put it in file.txt and changed the names to protect the innocent.

cat file.txt
; generated by /sbin/dhclient-script
search ab.some.place.us
nameserver 123.123.123.12
nameserver 145.145.145.14
nameserver 122.122.122.12


head -n3 file.txt | cut -d" " -f2
generated
ab.some.place.us
123.123.123.12


Using sed, I can pick out one or more lines individually....
Code:
sed -n 3p file.txt | cut -d" " -f2
123.123.123.12
 
Old 02-07-2006, 08:26 AM   #4
WilliamsJD
LQ Newbie
 
Registered: Nov 2003
Distribution: Fedora Core 4
Posts: 11

Rep: Reputation: 0
I'd usually use AWK for cherry-picking data from a file like that:

awk '/^nameserver/ {print $2; exit;}' file.txt

would give you the second field of the first line starting with "nameserver".
 
Old 02-08-2006, 06:11 AM   #5
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 660
Blog Entries: 6

Original Poster
Rep: Reputation: 31
Thank you all guys...all the method worked...well I think I need to learn how to do that...I think I will start with sed...

Edit: Ive got this script in my firewall to get the ppp IP dynamically...

EXT_IP="`/sbin/ifconfig ppp0 | grep 'inet addr' | awk '{print $2}' | sed -e 's/$

There is grep, awk and sed... which is better for what...I mean is one better in doing one job than another...?

Last edited by ALInux; 02-08-2006 at 06:14 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Xlib: extension "XFree86-DRI" missing on display ":0.0"." zaps Linux - Games 9 05-14-2007 03:07 PM
Video Card Nvidia Driver Xlib: extension "GLX" missing on display ":0.0". HELP! badgerbox76 Linux - Newbie 35 03-08-2007 02:27 AM
Video Card Nvidia Driver Xlib: extension "GLX" missing on display ":0.0". badgerbox76 Linux - Games 13 01-11-2006 04:47 PM
bash-2.05b# Xlib: extension "XFree86-DRI" missing on display ":0.0". citrus Linux - General 8 02-22-2004 10:43 AM


All times are GMT -5. The time now is 07:12 PM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration