.TH "RECUT" "1" "31 Dec 2013" "0.1" "RECUT" .SH NAME recut \- reorder, duplicate and remove sections from each line .SH SYNOPSIS .B recut .B \-b .I field-list .RB "[\| " \-o .IR delim " \|]" .RB "[\| " -- " \|]" .RI "[\| " file "... \|]" .B recut .B \-c .I field-list .RB "[\| " \-o .IR delim " \|]" .RB "[\| " -- " \|]" .RI "[\| " file "... \|]" .B recut .B \-f .I field-list .RB "[\| " \-d .IR delim " \|]" .RB "[\| " \-o .IR delim " \|]" .RB "[\| " \-s " \|]" .RB "[\| " -- " \|]" .RI "[\| " file "... \|]" .B recut .I long-options .RB "[\| " -- " \|]" .RI "[\| " file "... \|]" .B recut .B \-\-version .SH DESCRIPTION .B recut reads all files (or standard input) and processes them line by line. It splits each line into fields at a delimiter (by default a tab character), and then outputs those fields according to a specified field list. Fields can thus be suppressed, reordered and duplicated. The output fields are separated by another delimiter (by default also tab). The result is printed on standard output. Instead of fields separated by a delimiter, .B recut can also reorder the bytes or characters of each line. The special file name .B \- means the standard input. A pair of dashes .RB ( \-\- ) may be used to separate the options from the file arguments. This may be useful if a file name starts with a dash. All output lines end with a newline. If the last line of the input is missing a newline, one is added automatically. .SH OPTIONS .TP 10 .BI \-\-bytes= field-list Outputs exactly the specified bytes from each input line, with the .I output-delimiter between them (see .BR \-\-output-delimiter ). The first byte of each line is numbered 1. It is not an error if the .I field-list specifies bytes beyond the length of the line: those bytes will not be printed. But the .I output-delimiter will still be printed. .TP .BI \-b " field-list" Same as .BI \-\-bytes= field-list .TP .BI \-\-character= field-list Outputs the specified characters from each line of the input, with the .I output-delimiter between them (see .BR \-\-output-delimiter ). The first character of each line is numbered 1. It is not an error if the .I field-list specifies bytes beyond the length of the line: those bytes will not be printed. But the .I output-delimiter will still be printed. The input is interpreted according to the encoding part of the current locale. .TP .BI \-c " field-list" Same as .BI \-\-characters= field-list .TP .BI \-\-fields= field-list Outputs the specified fields from each line of the input, with the .I output-delimiter between them (see .BR \-\-output-delimiter ). The first field is numbered 1. It is not an error if the .I field-list argument specifies fields beyond the length of the line: those fields are considered to be empty. The .I output-delimiter will still be printed between them. .TP .BI \-f " field-list" Same as .BI \-\-fields= field-list .TP .BI \-\-delimiter= delim Specifies the delimiter that separates the fields in each line. The default is a tab character. Unlike in .BR cut (1), the .I delim may consist of more than one character. This option only has an effect in combination with .BR \-\-fields . .TP .BI \-d " delim" Same as .BI \-\-delimiter= delim .TP .BI \-\-output-delimiter= delim Specifies the delimiter that is inserted between fields, bytes or characters in the output. The default is the empty string in the case of .B \-\-bytes and .BR \-\-characters . When .B \-\-fields is used, the default is to use the same delimiter as for splitting the input, i.e., the same as .BR \-\-delimiter . .TP .BI \-o " delim" .TP .B \-\-only-delimited Suppress lines that do not contain at least one occurrence of .I delim (see .BR \-\-delimiter ). Only has effect in combination with .BR \-\-fields . .TP .B \-s Same as .B \-\-only-delimited .TP .B \-\-version Print the version number of .B recut and exit. .LP The equals sign (=) after long options may be replaced by spaces. .LP The .I field-list argument is a comma- or space-separated list of ranges. Each range is of the form .IR a\-b , where a and b are field numbers >= 1. This represents the range of fields from .I a to .IR b , inclusive. If .I a is 1, it may be omitted. Omitting .I b means "all remaining fields of the line". .I b may be less than .IR a , in which case the range is descending. Some examples: .TP .B 3\-5 The fields 3, 4 and 5. .TP .B 5\-3 The fields 5, 4 and 3, in that order. .TP .B \-5 The fields 1, 2, 3, 4 and 5. .TP .B 3\- The fields 3, 4, etc., until and including the last field in the line. (No fields are printed if the line has fewer than 3 fields.) .TP .B \- All fields of the line. .TP .B 3,2,1 The fields 3, 2 and 1. (The same as 3\-1.) .TP .B 2,1,3\- Fields 2 and 1 and then all other fields, if any. (Swaps the first two fields.) .LP An empty field list is allowed, e.g., .B \-\-fields="" (but all output lines will be empty). .SH EXAMPLES .TP 10 .B "recut \-d : \-f 1,3 /etc/passwd" Output the 1st and 3rd column of the passwd file. .TP .B "recut \-f 1,1,2,2,3\-" Duplicate the first two columns. Input is read from standard input. .TP .B "recut \-f 2,1,3\-" Swap the first two columns. Input is read from standard input. .TP .B "recut \-b \- myfile.txt" The output is the exact content of myfile.txt (except that a newline is added at the end if myfile.txt doesn't end with a newline). .TP .B "recut \-d :: \-f 2" Split lines from standard input into fields at occurrences of the 2-character string '::' and output only the second field of each line. .TP .B "recut -d ',' \-o ';' -f -" Copy input to output, replacing all commas by semicolons. (This is more efficiently done with .BR "tr ',' ';'" ) .SH "SEE ALSO" .BR setlocale (3)