% This file is embedded in datatool-user.pdf version 3.4 2025-04-03
% Example 98 Editing a Row of Data
% Label: "ex:selectandeditrow"
% arara: pdflatex
% arara: pdfcrop
\documentclass[12pt]{article}
\pagestyle{empty}
 \begin{filecontents}[noheader,overwrite]{customers.csv}
Id,Organisation,Surname,Forename,Email,Age
1,,Parrot,Polly,pp@example.com,42
2,University of Somewhere,Canary,Mabel,mc@example.com
3,University of Somewhere,Zebra,Zoë,zz@example.com,21
4,Zinnia Florestry,Arara,José,ja@example.com,42
5,,Duck,Dickie,dd@example.com,
6,Newt Fellowship,Axolotl,Lizzie,la@example.com
7,Avian Emporium,Canary,Fred,fc@example.com,19
8,Newt Fellowship,,Molgina,m@example.com
9,,Mander,Sally
10,Élite Emporium,Fant,Eli,ef@example.com,101
\end{filecontents}

\usepackage{datatool}
\DTLsetup{default-name=customers}
\DTLread{customers.csv} 
\begin{document}
% Edit ID 9
\DTLaction[key=Id,value=9]{select row}
\dtlreplaceentryincurrentrow
{Newt Fellowship}% new value
{\dtlcolumnindex{customers}{Organisation}}% column index
\dtlappendentrytocurrentrow
{Email}% column key
{sally.mander@example.com}% value
\dtlupdateentryincurrentrow
{Age}% column key
{23}% value
\dtlrecombine 

% Remove ID 2
\dtlgetrowforvalue{customers} {\dtlcolumnindex{customers}{Id}}% column index
{2}% value
\dtlrecombineomitcurrent 

\DTLaction{display} 
\end{document}