sábado, 26 de julio de 2014

Linux and Unix cut command

Linux and Unix cut command


About cut

Remove or "cut out" sections of each line of a file or files.

Syntax

cut OPTION... [FILE]...

Options

-b--bytes=LISTSelect only the bytes specified in LIST.
-c--characters=LISTSelect only the characters specified in LIST
-d--delimiter=DELIMuse DELIM instead of a tab for the field delimiter
-f--fields=LISTselect only these fields; also print any line that contains no delimiter character, unless the -s option is specified
-nThis option is ignored, but is included for compatibility reasons.
--complementcomplement the set of selected bytes, characters or fields.
-s--only-delimiteddo not print lines not containing delimiters.
--output-delimiter=STRINGuse STRING as the output delimiter string. The default is to use the input delimiter.
--helpDisplay a help message and exit.
--versionoutput version information and exit.

Usage Notes

When invoking cut, use the -b-c, or -f option, but only one of them.
Each LIST is made up of a range, or multiple ranges separated by commas. Selected input is written in the same order that it is read, and is written to output exactly once. Each range is one of:
Nthe Nth byte, character, or field, counted from 1.
N-from the Nth byte, character, or field, to the end of the line.
N-Mfrom the Nth to the Mth byte, character, or field (inclusive).
-Mfrom the first to the Mth byte, character, or field.
If no FILE is specified, cut reads from the standard input.

Examples

cut -c3 file.txt
Outputs the third character of every line of the file file.txt, cutting out the others.
cut -c1-3 file.txt
Outputs the first three characters of every line of the file file.txt, cutting out the rest.
cut -c3- file.txt
Outputs the third through the last characters of each line of the file file.txt, cutting out the firs two characters.
cut -c- file.txt
Outputs all of every line of the file file.txt, cutting out nothing.
cut -d':' -f1 /etc/passwd
Outputs the first field of the file /etc/passwd, where fields are delimited by a colon (':'). The first field of /etc/passwd is the username, so this command will output every username in the passwd file.
grep "/bin/bash" /etc/passwd | cut -d':' -f1,6
Outputs the first and sixth fields, delimited by a colon, of any entry in the/etc/passwd file which specifies /bin/bash. This command will output the username and home directory of any user whose login shell is /bin/bash.

Ver tambien
http://www.thegeekstuff.com/2013/06/cut-command-examples/

Related commands

No hay comentarios:

Publicar un comentario