How data extraction works in TextPipe
Extraction means pulling the pieces you need out of a file and discarding the rest. The source might be a 20 GB web server log, a folder of HTML pages, an XML feed or a report that was printed to a text file. The result is a smaller, structured file such as a CSV that a database, spreadsheet or script can load directly. TextPipe builds this as a list of filters that run in order on a stream of data. Because the file is processed in blocks rather than loaded into memory, the size of the input does not limit what you can extract.
Most extraction jobs combine three kinds of filter. A selection filter keeps only the lines, fields or pattern matches you want. A cleansing filter fixes what is left, for example trimming spaces or removing HTML tags. A formatting filter writes the output in the layout the next system expects. You can test the whole chain on a small sample, save it, and run the same filter list later from the command line or the COM interface without any programming.
Sample input and output
Suppose you need the client address, requested page and status code of every failed request from a web server log. Two input lines look like this:
203.0.113.7 - - [14/Mar/2024:10:22:41 +0000] "GET /pricing HTTP/1.1" 404 512
198.51.100.23 - - [14/Mar/2024:10:22:43 +0000] "GET /index.html HTTP/1.1" 200 8190
A filter that keeps only lines whose status code is 4xx or 5xx, followed by a pattern that captures the three fields, produces:
203.0.113.7,/pricing,404
The 200 response is dropped, and the surviving line is reduced to three comma-separated values. Run over a month of logs, the same filter list yields a file that opens directly in Excel for a broken-link report.
Typical settings
- Extract lines or fields: keep lines that match a pattern, or pick columns from delimited and fixed width records.
- Extract with a regular expression: use capture groups to return only part of each match. See the Perl-compatible regular expression guide for syntax.
- Remove duplicates: sort the output and drop repeated records so each value appears once.
- Process a folder: add many files or a whole directory tree and write one combined result or one output per input.
Practical applications
Web teams extract URLs and error codes from logs. Analysts pull invoice numbers and amounts out of printed reports that have no export option. Marketing teams collect product codes and prices from saved HTML pages. Data engineers use extraction as the first stage of an ETL job, shrinking raw feeds before they reach a loader. Because the filter list is saved, the job is repeatable and an auditor can see exactly which rules were applied.
Common pitfalls
- Patterns that work on a sample may miss rare formats. Test against a file that includes the worst records you know about.
- Greedy patterns can capture more than intended on lines with repeated delimiters. Use the non-greedy form or a more specific character class.
- Files in UTF-16 or an EBCDIC code page need to be converted first, or the pattern will not match the stored bytes.
Related pages
To target one data type, see extracting email addresses and extracting phone numbers. Sorting and de-duplicating the result is covered in sorting large files. The data mining solutions page and the database consulting case study show extraction in larger projects. For structured spreadsheet data, ExcelPipe applies similar rules to Excel workbooks.