The edit command performs editing of input fields in much the same way as the UNIX utility sed. In order to fully use this feature, you will need to understand regular expressions. For simple replacements, you may be better of using the map command.
See also: escape, trim. eval, map
Flag |
Req'd? |
Description |
-e cmd |
Yes |
Specifies the edit command to apply. The commands are modeled after those used by the sed stream editor. Currently only one command is implemented, the s(earch/replace) command: where: find is a regular expression to search for replace is the string to replace find with if found opts are options, which can be either i (ignore case) and/or g (replace all) Any number of commands can be specified - they will be applied sequentially. As with sed, you can use any character you like to separate the parts of the edit command, and it may be more convenient to so so. For example, this command changes all occurrences of two slashes ("//") to two minus signs ("--"): s://:--:g |
-f fields |
No |
Specifies a comma-separated list of fields to apply commands to. If none are specified, commands are applied to all fields. |
The following example removes the lower-case characters from the first field of the names.csv file:
csvfix edit -e 's/[a-z]//g' -f 1 data/names.csv
which produces:
"C","Dickens","M"
"J","Austen","F"
"H","Melville","M"
"F","O'Brien","M"
"G","Elliot","F"
"V","Woolf","F"
"O","Wilde","M"
The next example changes the M/F sex indicators into "Male" or "Female"
csvfix edit -e 's/M/Male/' -e 's/F/Female/' -f 3 data/names.csv
producing:
"Charles","Dickens","Male"
"Jane","Austen","Female"
"Herman","Melville","Male"
"Flann","O'Brien","Male"
"George","Elliot","Female"
"Virginia","Woolf","Female"
"Oscar","Wilde","Male"
This example shows recall of a patterns value, enclosing the sex indicator in a colon pair:
csvfix edit -e 's/\([MF]\)/:\1:/' -f 3 data/names.csv
producing:
"Charles","Dickens",":M:"
"Jane","Austen",":F:"
"Herman","Melville",":M:"
"Flann","O'Brien",":M:"
"George","Elliot",":F:"
"Virginia","Woolf",":F:"
"Oscar","Wilde",":M:"
Created with the Personal Edition of HelpNDoc: Free CHM Help documentation generator