-
Notifications
You must be signed in to change notification settings - Fork 35
Functions
Patrick Hochstenbach edited this page Apr 14, 2016
·
14 revisions
Fix function manipulate fields in every item of a Catmandu Importer. For instance for the command below the title field will be upcased for every item in the input JSON array.
$ catmandu convert JSON --fix 'upcase(title)' < data.json
Fix functions can have zero or more arguments separated by commas:
vacuum() # Clean all empty fields in a record
upcase(title) # Upcase the title value
append(title,"-123") # Add -123 at the end of the title value
The arguments to a Fix function can be Fix paths or a literal string. Literal string can be quoted with double or single quotes.
append(title,"-123")
append(title,'foo bar')
In case of single quotes all the characters between quotes should be interpreted verbatim. When using double quotes, the values in quotes can be interpreted by some Fix functions.
replace_all(title,"My (.*) Pony","Our $1 Fish") # Replace 'My Little Pony' by 'Our Little Fish'
Some Fix functions accept zero or more options which need to be specified as a name : value:
sort_field(tags, reverse:1) # Sort the tags field in reverse order
lookup("title","dict.csv", sep_char:'|',default:'NONE') # Lookup a title in a CSV file