### Building pdfgrep from Source Source: https://gitlab.com/pdfgrep/pdfgrep/-/blob/master/README.md Standard procedure for building pdfgrep from its source code using autotools. Includes steps for initial setup and installation. ```bash ./configure make sudo make install ``` -------------------------------- ### Example pdfgrep Command Source: https://gitlab.com/pdfgrep/pdfgrep/-/blob/master/README.md Demonstrates how to use pdfgrep to search for a pattern in a PDF file, showing options for limiting results, showing context, including filenames, and displaying page numbers. ```bash $ pdfgrep --max-count 1 --context 1 --with-filename --page-number pattern rabin-karp.pdf rabin-karp.pdf-1-randomized rabin-karp.pdf:1:pattern-matching rabin-karp.pdf-1-algorithms ``` -------------------------------- ### Uninstalling pdfgrep Source: https://gitlab.com/pdfgrep/pdfgrep/-/blob/master/README.md Command to uninstall pdfgrep after it has been built and installed. ```bash sudo make uninstall ``` -------------------------------- ### Combining pdfgrep with Unix Tools Source: https://context7.com/pdfgrep/pdfgrep/llms.txt pdfgrep integrates seamlessly with standard Unix command-line utilities for creating powerful and complex text processing workflows. Examples include piping to xargs, using find for file selection, and parallel processing. ```bash # Find PDFs containing "bar" and search those for "foo" pdfgrep -Z -l "bar" *.pdf | xargs -0 pdfgrep -H "foo" # Search PDFs smaller than 12MB find . -name "*.pdf" -size -12M -print0 | xargs -0 pdfgrep "pattern" # Parallel search on multicore systems using GNU parallel find . -name "*.pdf" -print0 | parallel -q0 pdfgrep -H "pattern" # Count occurrences across all PDFs and sort pdfgrep -c "keyword" *.pdf | sort -t: -k2 -n -r ``` -------------------------------- ### Building pdfgrep from Git Version Source: https://gitlab.com/pdfgrep/pdfgrep/-/blob/master/README.md Instructions for building the development version of pdfgrep obtained from a git repository. Requires running autogen.sh before the standard build process. ```bash ./autogen.sh ./configure make sudo make install ``` -------------------------------- ### pdfgrep Configure Options Source: https://gitlab.com/pdfgrep/pdfgrep/-/blob/master/README.md Illustrates common configuration options for the ./configure script when building pdfgrep. These options allow customization of features like accent stripping, shell completion, and regex engine support. ```bash # Build with experimental libunac support ./configure --with-unac # Configure installation directory for shell completion files ./configure --with-zsh-completion ./configure --with-bash-completion # Disable support for perl compatible regular expressions ./configure --without-libpcre # Disable manpage generation ./configure --disable-doc ``` -------------------------------- ### Display Context Lines for PDF Matches Source: https://context7.com/pdfgrep/pdfgrep/llms.txt Shows lines surrounding the matched pattern to provide context. The -A option displays lines after the match, -B displays lines before, and -C displays both. This helps in understanding the relevance of the match. ```bash # Show 2 lines of context around matches pdfgrep -C 2 "exception" code_review.pdf # Output: # try { # processData(); # } catch (exception& e) { # handleError(e); # logException(e); # -- # Unhandled exception in module ``` -------------------------------- ### List Files with/without Matches (-l, -L) Source: https://context7.com/pdfgrep/pdfgrep/llms.txt The -l option lists only the names of files that contain the specified pattern, while -L lists only the names of files that do not contain the pattern. This is useful for file management and filtering. ```bash # List files containing the pattern pdfgrep -l "DRAFT" *.pdf # Output: # proposal_v1.pdf # report_draft.pdf # List files NOT containing the pattern pdfgrep -L "APPROVED" *.pdf # Output: # pending_review.pdf # draft_document.pdf ``` -------------------------------- ### Case-Insensitive Search in PDF Source: https://context7.com/pdfgrep/pdfgrep/llms.txt Enables case-insensitive matching for both the search pattern and the content within PDF files. This is useful for finding variations of a word regardless of capitalization. Achieved using the -i or --ignore-case flags. ```bash # Search for "ERROR" regardless of case pdfgrep -i "error" logfile.pdf # Output: # ERROR: Connection failed # error: Invalid input detected # Error handling in section 3.2 ``` -------------------------------- ### Enable Caching for Performance (--cache) Source: https://context7.com/pdfgrep/pdfgrep/llms.txt The --cache option enables caching of the extracted PDF text, which can dramatically speed up repeated searches on the same large PDF files. Subsequent searches on the same file will leverage the cached text. ```bash # Enable caching for faster repeated searches pdfgrep --cache "pattern" large_document.pdf # Subsequent searches on the same file will be faster pdfgrep --cache "another_pattern" large_document.pdf ``` -------------------------------- ### Null-Byte Separator (-Z, --null) Source: https://context7.com/pdfgrep/pdfgrep/llms.txt The -Z or --null option uses null bytes as separators instead of newlines or colons. This is crucial for safely handling filenames that contain special characters, spaces, or newlines when piping output to other commands like xargs. ```bash # Safe handling of files with special characters in names pdfgrep -lZ "pattern" *.pdf | xargs -0 rm # Pipe to xargs safely pdfgrep -Z --files-with-matches "data" *.pdf | xargs -0 pdfgrep -H "related" ``` -------------------------------- ### Count Matches in PDF Files Source: https://context7.com/pdfgrep/pdfgrep/llms.txt Counts the occurrences of a pattern within PDF files instead of displaying the matching lines. Use -c for the total count per file or -p for the count per page. This is useful for summarizing search results. ```bash # Count total matches per file pdfgrep -c "the" document.pdf # Output: # 142 # Count matches per page pdfgrep -p "function" manual.pdf # Output: # manual.pdf:1:5 # manual.pdf:3:12 # manual.pdf:7:8 ``` -------------------------------- ### Display Page Numbers in PDF Search Results Source: https://context7.com/pdfgrep/pdfgrep/llms.txt Adds the page number to each matching line in the output, indicating where the pattern was found. The --page-number=label option can be used to display PDF page labels instead of numeric indices. Useful for referencing specific locations within a document. ```bash # Show page numbers with matches pdfgrep -n "introduction" thesis.pdf # Output: # 1:Introduction to the research problem # 5:See introduction for background # Show PDF page labels (e.g., "i", "ii", "1", "2") pdfgrep --page-number=label "introduction" thesis.pdf # Output: # i:Introduction to the research problem # 4:See introduction for background ``` -------------------------------- ### Control Colored Output (--color) Source: https://context7.com/pdfgrep/pdfgrep/llms.txt The --color option controls the highlighting of matched text in the output. Options include 'always', 'never', or 'auto' (default, enabled for terminals). Colors can be customized via the GREP_COLORS environment variable. ```bash # Force colored output even when piping pdfgrep --color=always "highlight" document.pdf | less -R # Disable colors pdfgrep --color=never "plain" document.pdf # Colors are customizable via GREP_COLORS environment variable export GREP_COLORS='ms=01;34:fn=35:ln=32:se=36' pdfgrep "pattern" document.pdf ``` -------------------------------- ### Search Password-Protected PDFs (--password) Source: https://context7.com/pdfgrep/pdfgrep/llms.txt The --password option enables searching within PDF files that are protected by a password. You can provide a single password or multiple passwords to try. ```bash # Search password-protected PDF pdfgrep --password="secret123" "confidential" encrypted.pdf # Try multiple passwords pdfgrep --password="pass1" --password="pass2" "data" protected.pdf ``` -------------------------------- ### Basic Search in PDF Source: https://context7.com/pdfgrep/pdfgrep/llms.txt Performs a basic search for a pattern within a specified PDF file. It returns lines containing the pattern and highlights the matches. This is the fundamental usage of pdfgrep. ```bash # Basic search for "algorithm" in a PDF file pdfgrep "algorithm" document.pdf # Output: # This chapter discusses the algorithm used for sorting. # The algorithm complexity is O(n log n). ``` -------------------------------- ### Quiet Mode for Scripting (-q, --quiet) Source: https://context7.com/pdfgrep/pdfgrep/llms.txt Quiet mode (-q or --quiet) suppresses all output and exits immediately after finding the first match. This is ideal for use in scripts where only the exit code is needed to determine if a pattern exists. ```bash # Check if pattern exists (exit 0 if found, 1 if not) if pdfgrep -q "approved" contract.pdf; then echo "Contract is approved" else echo "Approval not found" fi ``` -------------------------------- ### Search Multiple Patterns (-e, -f) Source: https://context7.com/pdfgrep/pdfgrep/llms.txt pdfgrep supports searching for multiple patterns using either the -e option for patterns specified directly on the command line or the -f option to read patterns from a file. This allows for OR logic between patterns. ```bash # Search for multiple patterns (OR logic) pdfgrep -e "error" -e "warning" -e "critical" system.pdf # Output: # ERROR: Disk full # Warning: Memory low # CRITICAL: System failure # Read patterns from file cat patterns.txt # error # warning # exception pdfgrep -f patterns.txt application.pdf ``` -------------------------------- ### Recursive PDF Search Source: https://context7.com/pdfgrep/pdfgrep/llms.txt Searches for patterns in all PDF files within a directory tree. The -r flag performs a recursive search while skipping symbolic links, and -R follows symbolic links. This is efficient for searching large collections of documents. ```bash # Search all PDFs in current directory recursively pdfgrep -r "confidential" . # Output: # ./reports/2023/q1.pdf:1:CONFIDENTIAL - Internal Use Only # ./contracts/vendor.pdf:2:This confidential agreement... # Search with specific include pattern pdfgrep -r --include "report*.pdf" "summary" /documents/ ``` -------------------------------- ### Filter Files in PDF Search Source: https://context7.com/pdfgrep/pdfgrep/llms.txt Allows filtering of files to be searched using glob patterns. The --include option specifies which files to search, while --exclude omits certain files. The default include pattern is '*.[Pp][Dd][Ff]'. ```bash # Only search files matching pattern pdfgrep -r --include "invoice*.pdf" "total" /accounting/ # Exclude certain files pdfgrep -r --exclude "draft*.pdf" "final" /documents/ # Combine include and exclude pdfgrep -r --include "*.pdf" --exclude "backup*" "keyword" . ``` -------------------------------- ### Control Filename Display in PDF Search Source: https://context7.com/pdfgrep/pdfgrep/llms.txt Manages the display of filenames in the search output. By default, filenames are shown when searching multiple files. The -H or --with-filename flag forces filename display, while -h or --no-filename suppresses it. ```bash # Force filename display even with single file pdfgrep -H "data" report.pdf # Output: # report.pdf:The data shows significant trends # Search multiple files (filenames shown by default) pdfgrep "conclusion" *.pdf # Output: # paper1.pdf:In conclusion, we demonstrated... # paper2.pdf:The conclusion supports our hypothesis ``` -------------------------------- ### Limit Match Count (-m, --max-count) Source: https://context7.com/pdfgrep/pdfgrep/llms.txt The -m or --max-count option stops searching a file after a specified number of matches have been found. This can significantly speed up searches on large files when only a few occurrences are needed. ```bash # Find first 5 matches pdfgrep -m 5 "error" large_logfile.pdf # First match per file with filename and page pdfgrep -m 1 -H -n "keyword" *.pdf ``` -------------------------------- ### Use PCRE for Advanced PDF Regex Source: https://context7.com/pdfgrep/pdfgrep/llms.txt Enables the use of Perl-Compatible Regular Expressions (PCRE) for more advanced pattern matching capabilities, such as lookahead, lookbehind, and non-greedy quantifiers. Requires pdfgrep to be compiled with libpcre2 support. ```bash # Use PCRE for complex patterns pdfgrep -P "(?<=price:\s)\d+\.\d{2}" invoice.pdf # Output: # 199.99 # 45.00 # Non-greedy matching pdfgrep -P ".*?" document.pdf ``` -------------------------------- ### Extract Only Matching Portions (-o) Source: https://context7.com/pdfgrep/pdfgrep/llms.txt The -o or --only-matching option prints only the matched portions of lines, rather than the entire line. This is useful for extracting specific data like email addresses from a PDF. ```bash # Extract only email addresses pdfgrep -o -P "[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}" contacts.pdf # Output: # john.doe@example.com # support@company.org # info@website.net ``` -------------------------------- ### Filter Search by Page Range (--page-range) Source: https://context7.com/pdfgrep/pdfgrep/llms.txt The --page-range option allows you to limit the search to specific pages or a range of pages within a PDF document. This is helpful for focusing searches on relevant sections. ```bash # Search only pages 1-10 pdfgrep --page-range "1-10" "abstract" thesis.pdf # Search specific pages pdfgrep --page-range "1,5,10-15,20" "keyword" document.pdf # Search first 5 pages pdfgrep -n --page-range "1-5" "introduction" book.pdf ``` -------------------------------- ### Fixed String Search in PDF Source: https://context7.com/pdfgrep/pdfgrep/llms.txt Treats the search pattern as a literal string rather than a regular expression. This is useful when searching for patterns that contain special regex characters, ensuring they are matched exactly. ```bash # Search for literal string with regex metacharacters pdfgrep -F "price = $100.00" receipt.pdf # Output: # Total price = $100.00 (tax included) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.