trim

Commands ››
Parent Previous Next

The trim command removes leading and/or trailing white space (spaces and tabs) from input fields, or truncates fields to a specific width. By default, both leading and trailing spaces are trimmed, but you can change this with the -l and -t flags described below.

See also: edit

Flag

Req'd?

Description

-f fields

No

Species list of fields to trim. If no fields are specified, all fields are trimmed.

-l

No

Trims leading white space.

-t

No

Trims trailing white space.

-w widths

No

Trims fields to widths by removing rightmost characters.

The widths parameter is a comma-separated list of width values. A negative value means that the field should not be trimmed. If the -f flag is also used, the width values refer to the fields specified by that flag, otherwise they are 1-based. White space trimming (both leading and trailing) is always performed before width trimming.



The following example trims both leading and trailing whitespace from the spaces.csv file:

csvfix trim data/spaces.csv

which produces:

"1","leading"
"2","trailing"
"3","both"

This example truncates all fields in names.csv to a single character:

csvfix trim -w 1,1,1 data/names.csv

producing:

"C","D","M"
"J","A","F"
"H","M","M"
"F","O","M"
"G","E","F"
"V","W","F"
"O","W","M"


Created with the Personal Edition of HelpNDoc: iPhone web sites made easy