views:

127

answers:

2

What do these successive cut commands do?

cut -f2 -d'"' | cut -f1 -d':'
+2  A: 

It means take the second field (-f2) as separated by double quote marks (-d'"', which the shell parses to -d' before running cut) , and then the first field (-f1) of that as separated by colons (-d:).

For instance, Phil Miller"developer:junior will be processed to developer. This is a very contrived example, and it would be useful to see what is actually being used as input to that pipeline.

Novelocrat
Note that if the line does not start with a quote, this will take what you'd read as the first quoted string in the line, while if it does start with a quote, it'll grab what's after the second quote.
Jefromi
+1  A: 

The "-f" is the "field specifier" and the "-d" is the delimiter.

The command above says to first cut the line up using '"' as the delimiter and return back the 2nd field ('-f2'). The second command cuts up that result using the ':' delimiter and returns back the 1st field.

Cut is useful for parsing through csv-like files, which have potentially embedded delimiters.

Andy White