Skip to main content

## merge

The merge command merges together two or more input fields into a single field on output. It is useful for creating composite names from components, for example creating a person's full name from their forename and surname.

See also: split_char, printf, template

Flag | Req'd? | Description
-f fields | No | Specifies a comma-separated list of fields to merge together. If this flag is used, at least two fields must be specified. If the flag is omitted, all fields are merged into a single output field.
-s sep | No | Specifies the character(s) that will be used to separate the merged fields. Default is a single space. The following special characters can be used: \t replaced by tab \n replaced by new line \r replaced by carriage return \\ replaced by single backslash All other characters are treated literally.
-p position | No | Specifies the position at which the merged fields will be inserted in the output. By default, the position is that of the first field specified by the -f flag.
-k | No | If supplied, indicates that the fields that were merged should be retained in the output - the default is to remove them.

The following example merges the first two fields (forename and surname) of the names.csv file to produce a single name (using the -f flag) but retaining the original fields (using the -k flag). It then positions the single name at the end of the output rows, the fourth output field (using the -p flag):

csvfix merge -f 1,2 -k -p 4 data/names.csv

which produces:

"Charles","Dickens","M","Charles Dickens"

"Jane","Austen","F","Jane Austen"

"Herman","Melville","M","Herman Melville"

"Flann","O'Brien","M","Flann O'Brien"

"George","Elliot","F","George Elliot"

"Virginia","Woolf","F","Virginia Woolf"

"Oscar","Wilde","M","Oscar Wilde"

Created with the Personal Edition of HelpNDoc: Easily create EPub books

####