Cut counting consecutive delimiters as fields


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cut counting consecutive delimiters as fields
# 1  
Old 01-13-2016
Cut counting consecutive delimiters as fields

When cut encounters consecutive delimiters it seems to count each instance as a field, at least with spaces. Is this typical behavior for any delimiter?

Code:
#:~$ ifconfig eth0 | grep HWaddr
eth0      Link encap:Ethernet  HWaddr 94:de:80:a7:6d:e1  
#:~$ ifconfig eth0 | grep HWaddr | cut -d " " -f 11
94:de:80:a7:6d:e1

# 2  
Old 01-14-2016
Yes, with cut every occurrence of the delimiter separates a field.


--
The default delimiter in awk does not. Try:
Code:
ifconfig eth0 | awk '/HWaddr/{print $5}'

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 01-14-2016
As a side note, if you want to know the mac assigned to an interface, in a Linux system just read it from /sys:
Code:
cat /sys/class/net/eth0/address

Much faster.
This User Gave Thanks to Aia For This Post:
# 4  
Old 01-14-2016
Thank you. Awk's default behavior is easy to grasp, but I am trying to understand this cut example in the book. Just trying to understand the counting principle at work here. It just seems a field pops out of nowhere. for example:

Code:
word1 word2

- one delimiter, two fields
Code:
word1  word2

- two consecutive delimiters in a row, 4 fields
Code:
word1   word2

- 3 consecutive delimiters in a row, 5 fields

Correct? In the first example the delimiter is not counted as a field, but with consecutive occurrences we simply count each one as an occurrence of a field.

Last edited by Riker1204; 01-14-2016 at 01:58 AM..
# 5  
Old 01-14-2016
No, there is always one more fields than delimiters.
Between consecutive delimiters there is an empty field.
These 2 Users Gave Thanks to MadeInGermany For This Post:
# 6  
Old 01-14-2016
Got it. Thank you all for the help. Marking as solved.
# 7  
Old 01-18-2016
BTW some versions of cut has -F option that folds adjacent delimiters into one
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Cut between two delimiters, / and .

BASH : I have a very long list I am parsing through: 10/10/19... (5 Replies)
Discussion started by: jeffs42885
5 Replies

2. UNIX for Beginners Questions & Answers

find pattern matches in consecutive lines in certain fields-awk

I have a text file with many thousands of lines, a small sample of which looks like this: InputFile:PS002,003 D -1 5 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 6 6 -1 -1 -1 -1 0 509 0 PS002,003 PSQ 0 1 7 18 1 0 -1 1 1 3 -1 -1 ... (5 Replies)
Discussion started by: jvoot
5 Replies

3. Shell Programming and Scripting

Getting fields from a file having multiple delimiters

Hi All, I have a file with a single row having the following text ABC.ABC.ABC,Database,New123,DBNAME,F,ABC.ABC.ABC_APP,"@FUNCTION1("ENT1") ,@FUNCTION2("ENT2")",R, I want an output in the following format ABC.ABC.ABC DBNAME ABC.ABC.ABC_APP '@FUNCTION1("ENT1")... (3 Replies)
Discussion started by: dev.devil.1983
3 Replies

4. UNIX for Beginners Questions & Answers

Cut command: can't make it cut fields

I'm a complete beginner in UNIX (and not a computer science student either), just undergoing a tutoring course. Trying to replicate the instructions on my own I directed output of the ls listing command (lists all files of my home directory ) to My_dir.tsv file (see the screenshot) to make use of... (9 Replies)
Discussion started by: scrutinizerix
9 Replies

5. Shell Programming and Scripting

Counting a consecutive number in column 2

Hi, I have a input file which contains following data 0 1 0 2 0 3 0 4 0 8 0 9 0 11 1 1 1 2 1 6 1 7 1 8 1 9 2 1 2 11 2 12 (12 Replies)
Discussion started by: Ryan Kim
12 Replies

6. UNIX for Dummies Questions & Answers

Cut fields between delimiters

I'm having bother getting both lines contained in a file to output as the same value. A simple example: john:123456:123:456:doe john:123456:123:doe cut -d: -f1,4 input file john:456 john:doe ^ first line should be same as second. trick one for me, i know why it's because of the... (4 Replies)
Discussion started by: landofus
4 Replies

7. Shell Programming and Scripting

Script in SED and AWK so that it treats consecutive delimiters as one

Hi All, I am trying to cut to do a cut operation, but since there are seems to be more than one deltimiters in some occasion I am not able to get the exact field. Can you please provide an SED and AWK script for treating the source file in such a way that all consecutive delimiters are treated... (3 Replies)
Discussion started by: rakesh.su30
3 Replies

8. Shell Programming and Scripting

cut -- line with no delimiters

I just discovered, to my dismay, the following part of the cut man page: -f, --fields=LIST select only these fields; also print any line that contains no delimiter character, unless the -s option is specified The -s option toggles the printing of lines with no delimiters. In most... (3 Replies)
Discussion started by: chlorine
3 Replies

9. Shell Programming and Scripting

awk sed cut? to rearrange random number of fields into 3 fields

I'm working on formatting some attendance data to meet a vendors requirements to upload to their system. With some help on the forums here, I have the data close. But they've since changed what they want. The vendor wants me to submit three fields to them. Field 1 is the studentid field,... (4 Replies)
Discussion started by: axo959
4 Replies

10. Shell Programming and Scripting

Cut based on Two Delimiters at one go

Hi I wanted to cut the feilds comming after % and After $ at one go can we do some thing like this cut -f 2 -d "%|$" (But it doesnot work) Input File BWPG %TCPRP1 $SCSPR000 BWPH %TCPRP1 $SCSPR003 BWPI %TRTYUP ResourceDescription="IMPRIMANTE " $BWOPTY BWPJ %ZOMBIE ... (4 Replies)
Discussion started by: pbsrinivas
4 Replies
Login or Register to Ask a Question