-
Notifications
You must be signed in to change notification settings - Fork 473
CSV Input Filtering
- Python Regular Expressions Search function
- Definitions
- Quoting rules
- Column row filtering
- Column row limiting
- Saving filters in gam.cfg
- Validate filters
There are two values in gam.cfg
that can be used to filter the input from gam csv
commands.
-
csv_input_row_filter
- A list or JSON dictionary used to include specific rows based on column values -
csv_input_row_drop_filter
- A list or JSON dictionary used to exclude specific rows based on column values
These filters can be used alone or in conjunction with the matchfield|skipfield <FieldName> <RegularExpression>
options.
<DataSelector> ::=
<ListSelector>|
<FileSelector>|
<CSVFileSelector>
<Date> ::=
<Year>-<Month>-<Day> |
(+|-)<Number>(d|w|y) |
never|
today
<Time> ::=
<Year>-<Month>-<Day>T<Hour>:<Minute>:<Second>[.<MilliSeconds>](Z|(+|-(<Hour>:<Minute>))) |
(+|-)<Number>(m|h|d|w|y) |
never|
now|today
<Operator> ::= <|<=|>=|>|=|!=
<RegularExpression> ::= <String>
See: https://docs.python.org/3/library/re.html>
<FieldNameFilter> :: = <RegularExpression>
<RowValueFilter> ::=
[(any|all):]boolean:<Boolean>|
[(any|all):]count<Operator><Number>|
[(any|all):]countrange!=<Number>/<Number>|
[(any|all):]countrange=<Number>/<Number>|
[(any|all):]data:<DataSelector>|
[(any|all):]date<Operator><Date>|
[(any|all):]daterange!=<Date>/<Date>|
[(any|all):]daterange=<Date>/<Date>|
[(any|all):]length<Operator><Number>|
[(any|all):]lengthrange!=<Number>/<Number>|
[(any|all):]lengthrange=<Number>/<Number>|
[(any|all):]notdata:<DataSelector>|
[(any|all):]notregex:<RegularExpression>|
[(any|all):]notregexcs:<RegularExpression>|
[(any|all):]regex:<RegularExpression>|
[(any|all):]regexcs:<RegularExpression>|
[(any|all):]text<Operator><String>|
[(any|all):]textrange!=<String>/<String>|
[(any|all):]textrange=<String>/<String>|
[(any|all):]time<Operator><Time>|
[(any|all):]timeofdayrange!=<Hour>:<Minute>/<Hour>:<Minute>|
[(any|all):]timeofdayrange=<Hour>:<Minute>/<Hour>:<Minute>|
[(any|all):]timerange!=<Time>/<Time>|
[(any|all):]timerange=<Time>/<Time>|
<RowValueFilterList> ::=
"'<FieldNameFilter>:<RowValueFilter>'(,'<FieldNameFilter>:<RowValueFilter>')*"
<RowValueFilterJSONList> ::=
'{"<FieldNameFilter>": "<RowValueFilter>"(,"<FieldNameFilter>": "<RowValueFilter>")*}' |
"{\"<FieldNameFilter>\": \"<RowValueFilter>\"(,\"<FieldNameFilter>\": \"<RowValueFilter>\")*}"
Name:value form.
<RowValueFilterList> ::=
"'<FieldNameFilter>:<RowValueFilter>'(,'<FieldNameFilter>:<RowValueFilter>')*"
-
<RowValueFilterList>
, even if it has one element, should be enclosed in"
. - Each
<FieldNameFilter>:<RowValueFilter>
pair should be enclosed in'
. - If
<FieldNameFilter>
contains a:
or a space, it should be enclosed in\"
. - If
<RegularExpression>
or<DataSelector>
in<RowValueFilter>
contain a space, it should be enclosed in\"
. - If
<FieldNameFilter>
or<RegularExpression>
in<RowValueFilter>
contain a\
to escape a special character or enter a special sequence, enter\\\
on Linux and Mac OS,\\
on Windows,
Examples:
csv_input_row_filter "'\"accounts:used_quota_in_mb\":count>15000'"
csv_input_row_filter "'email:data:\"csvfile gsheet:email user@domain.com FileID Sheet1\"'"
Linux and Mac OS
csv_input_row_filter "'phones.\\\d+.value:regex:(?:^\\\(510\\\) )|(?:^510[- ])\\\d{3}-\\\d{4}'"
Windows
csv_input_row_filter "'phones.\\d+.value:regex:(?:^\\(510\\) )|(?:^510[- ])\\d{3}-\\d{4}'"
JSON form.
<RowValueFilterJSONList> ::=
'{"<FieldNameFilter>": "<RowValueFilter>"(,"<FieldNameFilter>": "<RowValueFilter>")*}' |
"{\"<FieldNameFilter>\": \"<RowValueFilter>\"(,\"<FieldNameFilter>\": \"<RowValueFilter>\")*}"
- The first JSON form can be used on Linux and Mac OS; it can not be used on Windows.
- The second JSON form can be used on Linux, Mac OS and Windows.
- If
<FieldNameFilter>
contains a:
or a space, no additional quoting is required
Example:
csv_input_row_filter '{"accounts:used_quota_in_mb": "count>=150"}'
csv_input_row_filter "{\"accounts:used_quota_in_mb\": \"count>=150\"}"
Row filtering includes/excludes rows based on column values.
Field names are specified by regular expressions; at its simplest, you specify a complete field name. Field names are matched in a case insensitive manner.
If the field name doesn't contain any of the following regular expression characters ^$*+|$[{(
,
it will be surrounded with ^$
so that it doesn't match any subfields that begin with the field name as a prefix.
The following filter will match the count field and not the subfields.
config csv_input_row_filter "'externalIds:countrange=1/10'"
primaryEmail,externalIds,externalIds.0.type,externalIds.0.value,externalIds.1.type,externalIds.1.value,...
You can include rows for gam csv commands based on column values. You specify a list
of fields(headers) and the values they must have. csv_input_row_filter
is used to specify the
fields and values. Each field name/expression can appear only once in the list.
You specify whether all or any value filters must match for the row to be included in the input.
-
csv_input_row_filter_mode allmatch
- All value filters must match for the row to be included in the input; this is the default -
csv_input_row_filter_mode anymatch
- Any value filter must match for the row to be included in the input
gam config csv_input_row_filter <RowValueFilterList> ...
gam config csv_input_row_filter <RowValueFilterJSONList> ...
You can exclude rows for gam csv commands based on column values. You specify a list
of fields(headers) and the values they must not have. csv_input_row_drop_filter
is used to specify the
fields and values. Each field name/expression can appear only once in the list.
You specify whether all or any value filters must match for the row to be excluded from the input.
-
csv_input_row_filter_drop_mode allmatch
- If all value filters match, the row is excluded from the input -
csv_input_row_filter_drop_mode anymatch
- If any value filter matches, the row is excluded from the input; this is the default
gam config csv_input_row_drop_filter <RowValueFilterList> ...
gam config csv_input_row_drop_filter <RowValueFilterJSONList> ...
A filter matches if the field has the desired value. lf you specify a regular expression for a field name that matches
several columns, the filter matches if any of the columns has a match. In the case of notregex|notregexcs|notdata
,
the filter matches if none (not any) of the columns has a match.
<RowValueFilter>
allows specifying that the filter will match only if all of the columns have a match.
In the case of notregex|notregexcs|notdata
, the filter matches if some (not all) of the columns have a match.
If neither any
or all
is explicitly specified, any
is the default.
These are the row value filter types:
-
boolean:<Boolean>
- Used on fields with Boolean values; a blank field is considered False -
count<Operator><Number>
- Used on fields with numbers; a blank field will not match -
countrange=<Number>/<Number>
- Used on fields with numbers; a blank field will not match- The field value must be
>=
the left<Number>
and<=
the right<Number>
- The field value must be
-
countrange!=<Number>/<Number>
- Used on fields with numbers; a blank field will not match- The field value must be
<
the left<Number>
or>
the right<Number>
- The field value must be
-
data:<DataSelector>
- Used on fields with text; field value must match some value in<DataSelector>
; case sensitive -
date<Operator><Date>
- Used on fields with dates or times; only the date portion of a time field is compared; a blank field will not match -
daterange=<Date>/<Date>
- Used on fields with dates or times; only the date portion of a time field is compared; a blank field will not match- The field value must be
>=
the left<Date>
and<=
the right<Date>
- The field value must be
-
daterange!=<Date>/<Date>
- Used on fields with dates or times; only the date portion of a time field is compared; a blank field will not match- The field value must be
<
the left<Date>
or>
the right<Date>
- The field value must be
-
length<Operator><Number>
- Used on fields with strings; non string fields will not match -
lengthrange=<Number>/<Number>
- Used on fields with strings; non string fields will not match- The field length must be
>=
the left<Number>
and<=
the right<Number>
- The field length must be
-
lengthrange!=<Number>/<Number>
- Used on fields with strings; non string fields will not match- The field length must be
<
the left<Number>
or>
the right<Number>
- The field length must be
-
notdata:<DataSelector>
- Used on fields with text; field value must not match any value in<DataSelector>
; case sensitive -
notregex:<RegularExpression>
- Used on fields with text; field value must not match<RegularExpression>
; case insensitive -
notregexcs:<RegularExpression>
- Used on fields with text; field value must not match<RegularExpression>
; case sensitive -
regex:<RegularExpression>
- Used on fields with text; field value must match<RegularExpression>
; case insensitive -
regexcs:<RegularExpression>
- Used on fields with text; field value must match<RegularExpression>
; case sensitive -
text<Operator><String>
- Used on fields with text -
textrange=<String>/<String>
- Used on fields with strings- The field value must be
>=
the left<String>
and<=
the right<String>
- The field value must be
-
textrange!=<String>/<String>
- Used on fields with strings- The field value must be
<
the left<String>
or>
the right<String>
- The field value must be
-
time<Operator><Time>
- Used on fields with times; a blank field will not match -
timeofdayrange=<Hour>:<Minute>/<Hour>:<Minute>
- Used on fields with times; a blank field will not match- The field value must be
>=
the left<Hour>:<Minute>
and<=
the right<Hour>:<Minute>
- The field value must be
-
timeofdayrange!=<Hour>:<Minute>/<Hour>:<Minute>
- Used on fields with times; a blank field will not match- The field value must be
<
the left<Hour>:<Minute>
or>
the right<Hour>:<Minute>
- The field value must be
-
timerange=<Time>/<Time>
- Used on fields with times; a blank field will not match- The field value must be
>=
the left<Time>
and<=
the right<Time>
- The field value must be
-
timerange!=<Time>/<Time>
- Used on fields with times; a blank field will not match- The field value must be
<
the left<Time>
or>
the right<Time>
- The field value must be
In versions prior to 5.12.00
, regex:<RegularExpression>
and notregex:<RegularExpression>
were processed in a case sensitive manner;
in many cases this is probably not desirable; e.g., matching file names which are case insensitive.
Now, regex:<RegularExpression>
and notregex:<RegularExpression>
are processed in a case insensitive manner.
To get the prior case sensitive processing, use regexcs:<RegularExpression>
and notregexcs:<RegularExpression>
.
You want to process groups with 100 or more direct members.
gam redirect csv GroupInfo.csv print groups fields directmemberscount
gam config csv_input_row_filter "'directMembersCount:count>100'" csv GroupInfo.csv gam group "~email" ...
You want to process groups not created by an administrator.
gam redirect csv GroupInfo.csv print groups fields admincreated
gam config csv_input_row_drop_filter "'adminCreated:boolean:true'" csv GroupInfo.csv gam group "~email" ...
You want to process users created in the last 30 days.
gam redirect csv UserInfo.csv print users fields creationtime
gam config csv_input_row_filter "'creationTime:date>=-30d'" csv UserInfo.csv gam user "~primaryEmail" ...
You want to process users that are consuming more than 15GB of storage. Special quoting is required because the field name contains a colon.
gam redirect csv UserInfo.csv report user services accounts fields "accounts:used_quota_in_mb"
gam config csv_input_row_filter "'\"accounts:used_quota_in_mb\":count>15000'" csv UserInfo.csv gam user "~primaryEmail" ...
You can limit the number of rows read from a CSV file.
You want to process the first 10 users that are consuming more than 15GB of storage. Special quoting is required because the field name contains a colon.
gam redirect csv UserInfo.csv report user services accounts fields "accounts:used_quota_in_mb"
gam config csv_input_row_filter "'\"accounts:used_quota_in_mb\":count>15000'" csv_input_row_limit 10 csv UserInfo.csv gam user "~primaryEmail" ...
If you define a value for csv_input_row_filter
, csv_input_row_drop_filter
or csv_input_row_limit
in the [DEFAULT]
section of gam.cfg
,
it will apply to every gam csv
command which is probably not desirable. You can store them in gam.cfg
in named sections.
[Filter510]
csv_input_row_filter = 'phones.\\\d+.value:regex:(?:^\\\(510\\\) )|(?:^510[- ])\\\d{3}-\\\d{4}'
You want to process users with phone numbers in the area code 510; the number can be in the format (510) ddd-dddd
or 510-ddd-dddd
or 510 ddd-dddd
.
gam redirect csv UserInfo.csv print users fields name,phones
gam selectinputfilter Filter510 csv UserInfo.csv gam user "~primaryEmail" ...
Version 6.30.00
added the gam comment <String>*
command that can be used to validate input row filters.
$ more Comment.csv
col1,col2
aaa,111
bbb,222
ccc,333
$ gam config csv_input_row_drop_filter "col1:regex:bbb" csv Comment.csv gam comment "Col1:~~col1~~" "Col2:~~col2~~"
2022-12-16T12:41:50.045-08:00,0/2,Using 2 processes...
Col1:aaa Col2:111
Col1:ccc Col2:333
$ gam config csv_input_row_filter "col1:regex:bbb" csv Comment.csv gam comment "Col1:~~col1~~" "Col2:~~col2~~"
2022-12-18T09:42:26.108-08:00,0/1,Using 1 process...
Col1:bbb Col2:222
Need more help? Ask on the GAM Discussion Group
Update History
Installation
- How to Install GAM7
- How to Upgrade GAMADV-XTD3 to GAM7
- How to Upgrade Legacy GAM to GAM7
- How to Update GAM7
- Verifying a GAM7 Build is Legitimate and Official
- Install GAM as Python Library
- GAM7 on Chrome OS Devices
- GAM7 on Android Devices
- Google Network Addresses
- HTTPS Proxy
- SSL Root CA Certificates
- How to Uninstall GAM7
Configuration
- Authorization
- GAM Configuration
- Running GAM7 securely on a Google Compute Engine
- Using GAM7 with a delegated admin service account
- Using GAM7 with a YubiKey
- GAM with minimal GCP rights
Notes and Information
- Upgrade Benefits
- Questions? Visit the GAM Discussion Forum
- GAM Public Chat Room
- Scripts
- Other Resources
- Drive REST API v3
- BNF Syntax
- GAM Return Codes
- Python Regular Expressions
- Rclone
Definitions
Command Processing
- Bulk Processing
- Command Line Parsing
- Command Logging and Progress
- Command data from Google Docs/Sheets/Storage
- CSV Special Characters
- CSV Input Filtering
- CSV Output Filtering
- Meta Commands and File Redirection
- Permission matches
- Tag Replace
- Todrive
Collections
Client Access
- Addresses
- Administrators
- Alert Center
- Aliases
- Calendars
- Calendars - Access
- Calendars - Events
- Chrome Auto Update Expiration Counts
- Chrome Browser Cloud Management
- Chrome Device Needs Attention Counts
- Chrome Installed Apps
- Chrome Policies
- Chrome Printers
- Chrome Profile Management
- Chrome Version Counts
- Chrome Version History
- ChromeOS Devices
- Classroom - Courses
- Classroom - Guardians
- Classroom - Invitations
- Classroom - Membership
- Cloud Channel
- Cloud Identity Devices
- Cloud Identity Groups
- Cloud Identity Groups - Membership
- Cloud Identity Policies
- Cloud Storage
- Context Aware Access Levels
- Customer
- Domains
- Domains - Verification
- Domain People - Contacts & Profiles
- Domain Shared Contacts - Global Address List
- Email Audit Monitor
- Find File Owner
- Google Data Transfers
- Groups
- Groups - Membership
- Inbound SSO
- Licenses
- Mobile Devices
- Organizational Units
- Reports
- Reseller
- Resources
- Send Email
- Schemas
- Shared Drives
- Sites
- Users
- Unmanaged Accounts
- Users - Signout and Turn off 2-Step Verification
- Vault - Takeout
- Version and Help
Special Service Account Access
Service Account Access
- Users - Analytics Admin
- Users - Application Specific Passwords
- Users - Backup Verification Codes
- Users - Calendars
- Users - Calendars - Access
- Users - Calendars - Events
- Users - Chat
- Users - Classification Labels
- Users - Classroom - Profile
- Users - Deprovision
- Users - Contacts
- Users - Contacts - Delegates
- Users - Drive - File Selection
- Users - Drive - Activity/Settings
- Users - Drive - Cleanup
- Users - Drive - Comments
- Users - Drive - Copy/Move
- Users - Drive - Files-Display
- Users - Drive - Files-Manage
- Users - Drive - Orphans
- Users - Drive - Ownership
- Users - Drive - Permissions
- Users - Drive - Query
- Users - Drive - Revisions
- Users - Drive - Shortcuts
- Users - Drive - Transfer
- Users - Forms
- Users - Gmail - Client Side Encryption
- Users - Gmail - Delegates
- Users - Gmail - Filters
- Users - Gmail - Forwarding
- Users - Gmail - Labels
- Users - Gmail - Messages/Threads
- Users - Gmail - Profile
- Users - Gmail - S/MIME
- Users - Gmail - SendAs/Signature/Vacation
- Users - Gmail - Settings
- Users - Group Membership
- Users - Keep
- Users - Looker Studio
- Users - Meet
- Users - Classroom - Profile
- Users - People - Contacts & Profiles
- Users - Photo
- Users - Profile Sharing
- Users - Shared Drives
- Users - Spreadsheets
- Users - Tasks
- Users - Tokens
- Users - YouTube
GAM Tutorials
- Account Auditing
- Calendar Settings
- Chat Bot commands
- Chrome Browser Management
- Chrome Policy Settings
- Context Aware Access levels
- Data Transfers
- Domain Verification
- Google Drive Management
- Group Settings
- Inbound SSO Settings
- Managing Admins
- Managing Classroom
- Managing Custom User Schemas
- Managing Devices
- Managing Organizations
- Managing Product Licenses
- Managing Users, Groups, Aliases, Domains, Mobile and Chrome Devices, and Resource Calendars
- OAuth Authentication Related Commands
- Print Users, Groups, Aliases, Mobile and Chrome OS devices, OUs, Licenses and Reports
- Printers
- Unmanaged Users and Invitations
- User Email Settings
- User Security Settings