LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-13-2014, 10:41 AM   #1
sryzdn
Member
 
Registered: Feb 2013
Posts: 248

Rep: Reputation: 1
cut command --fields


Hi, I'm reading a book that has a command as follows:

Code:
$ ifconfig eth0 | grep HWaddr | cut -d " " -f 11
the cut command is to get the hardware address which is delimited from HWaddr by a space. I just cannot understand the option -f 11 (specially why 11). Also, how can I make sure that cut returns what coms after HWadd and not before it?
 
Old 10-13-2014, 10:44 AM   #2
linosaurusroot
Member
 
Registered: Oct 2012
Distribution: OpenSuSE,RHEL,Fedora,OpenBSD
Posts: 979
Blog Entries: 2

Rep: Reputation: 235Reputation: 235Reputation: 235
A sentence of words separated by spaces has field 11 HERE as seen by counting.
 
Old 10-13-2014, 10:46 AM   #3
sryzdn
Member
 
Registered: Feb 2013
Posts: 248

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by linosaurusroot View Post
A sentence of words separated by spaces has field 11 HERE as seen by counting.
What it returns is: 00:0C:76:96:A3:73.
I don't know how to relate "11" to it.
 
Old 10-13-2014, 11:03 AM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
hint: there are 6 " "'s (spaces) between eth0 and Link.
 
1 members found this post helpful.
Old 10-13-2014, 11:13 AM   #5
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,261

Rep: Reputation: 297Reputation: 297Reputation: 297
The cut command is very simple. It simply cuts between spaces, and when there are many after one another, it treats them as empty words. It works because of all those spaces after eth0. This might be more clear:


Code:
ifconfig eth0 | grep HWaddr | awk '{print $5}'
 
1 members found this post helpful.
Old 10-13-2014, 11:20 AM   #6
sryzdn
Member
 
Registered: Feb 2013
Posts: 248

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by schneidz View Post
hint: there are 6 " "'s (spaces) between eth0 and Link.
still not getting to "11"
 
Old 10-13-2014, 11:21 AM   #7
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
not sure what error you are receiving.

what is the command you are running ?
what is the result you are getting ?
what is the result you are expecting ?
 
Old 10-13-2014, 11:23 AM   #8
sryzdn
Member
 
Registered: Feb 2013
Posts: 248

Original Poster
Rep: Reputation: 1
Quote:
Originally Posted by schneidz View Post
not sure what error you are receiving.

what is the command you are running ?
what is the result you are getting ?
what is the result you are expecting ?
No error - I just didn't count the spaces between Ethernet and HWaddr
Now counting all spaces, I got to "11"
 
Old 10-13-2014, 06:03 PM   #9
joe_2000
Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 808

Rep: Reputation: 216Reputation: 216Reputation: 216
Quote:
Originally Posted by sryzdn View Post
still not getting to "11"
It means that it will return the 11th word, where words are delimited by spaces.
 
Old 10-13-2014, 06:06 PM   #10
joe_2000
Member
 
Registered: Jul 2012
Location: Aachen, Germany
Distribution: Void, Debian
Posts: 808

Rep: Reputation: 216Reputation: 216Reputation: 216
also, from the manpage (man cut):
Code:
       -f, --fields=LIST
              select only these fields;  also print any line that contains  no
              delimiter character, unless the -s option is specified
So it splits your line into fields, and gives you the content of the 11th field...
 
1 members found this post helpful.
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I cut fields with repeated delimiters? Mountain Linux - Software 4 11-19-2012 08:50 AM
[SOLVED] How to cut quoted fields out of a text file? scorbett Linux - General 4 10-13-2011 08:15 PM
need to cut fields smritisingh03 Linux - Newbie 1 01-25-2011 03:49 PM
Separating Fields from Output - cut command Hi_This_is_Dev Linux - General 3 08-28-2010 03:23 PM
cut fields in a file christina_rules Linux - Newbie 12 07-15-2006 11:00 AM


All times are GMT -5. The time now is 03:05 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration