### Configuration File Example Source: https://github.com/genivia/ugrep/blob/master/README.md Illustrates the format of a ugrep configuration file. Lines starting with '#' are comments. Options are specified as NAME=VALUE pairs. Empty lines are ignored. This example shows settings for colors, disabling hidden file searches, and specifying ignore files. ```ini # Color scheme colors=cx=hb:ms=hiy:mc=hic:fn=hi+y+K:ln=hg:cn=hg:bn=hg:se= # Disable searching hidden files and directories no-hidden # ignore files specified in .ignore and .gitignore in recursive searches ignore-files=.ignore ignore-files=.gitignore ``` -------------------------------- ### Install ugrep Source: https://github.com/genivia/ugrep/blob/master/README.md After building, use 'sudo make install' to install the ugrep and ug commands, along with their man pages and pattern files. ```bash $ sudo make install ``` -------------------------------- ### Install ugrep on OpenSUSE Source: https://github.com/genivia/ugrep/blob/master/README.md Use zypper to install ugrep on OpenSUSE systems. ```bash $ zypper install ugrep ``` -------------------------------- ### Install bzip3 library Source: https://github.com/genivia/ugrep/blob/master/README.md Install the bzip3 library using apt-get for searching .bz3 files in ugrep. ```bash sudo apt-get install -y bzip3 ``` -------------------------------- ### Install zlib development library Source: https://github.com/genivia/ugrep/blob/master/README.md Install the zlib development library using apt-get for compressed file searching in ugrep. ```bash sudo apt-get install -y libz-dev ``` -------------------------------- ### Install brotli development library Source: https://github.com/genivia/ugrep/blob/master/README.md Install the brotli development library using apt-get for searching .br files in ugrep. ```bash sudo apt-get install -y libbrotli-dev ``` -------------------------------- ### Get build options Source: https://github.com/genivia/ugrep/blob/master/README.md Run the build script with the --help flag to display available build configuration options. ```bash $ ./build.sh --help ``` -------------------------------- ### Install ugrep on Gentoo Source: https://github.com/genivia/ugrep/blob/master/README.md Install ugrep on Gentoo using the emerge package manager. ```bash $ emerge sys-apps/ugrep ``` -------------------------------- ### Install ugrep on OpenBSD Source: https://github.com/genivia/ugrep/blob/master/README.md Use pkg_add to install ugrep on OpenBSD systems. ```bash $ pkg_add ugrep ``` -------------------------------- ### Install bzip2 development library Source: https://github.com/genivia/ugrep/blob/master/README.md Install the bzip2 development library using apt-get for searching .bz and .bz2 files in ugrep. ```bash sudo apt-get install -y libbz2-dev ``` -------------------------------- ### Install ugrep with Scoop on Windows Source: https://github.com/genivia/ugrep/blob/master/README.md Install ugrep on Windows using the Scoop package manager. ```powershell scoop install ugrep ``` -------------------------------- ### Install lzma development library Source: https://github.com/genivia/ugrep/blob/master/README.md Install the lzma development library using apt-get for searching .lzma and .xz files in ugrep. ```bash sudo apt-get install -y liblzma-dev ``` -------------------------------- ### Install zstd development library Source: https://github.com/genivia/ugrep/blob/master/README.md Install the zstd development library using apt-get for searching .zst files in ugrep. ```bash sudo apt-get install -y libzstd-dev ``` -------------------------------- ### Install ugrep on FreeBSD Source: https://github.com/genivia/ugrep/blob/master/README.md Install ugrep on FreeBSD using the pkg package manager. ```bash $ pkg install ugrep ``` -------------------------------- ### Install ugrep on Haiku Source: https://github.com/genivia/ugrep/blob/master/README.md Use pkgman to install the ugrep command-line utility on Haiku systems. ```bash $ pkgman install cmd:ugrep ``` -------------------------------- ### Install ugrep on Alpine Linux Source: https://github.com/genivia/ugrep/blob/master/README.md Install ugrep and its documentation on Alpine Linux using the apk package manager. ```bash $ apk add ugrep ugrep-doc ``` -------------------------------- ### Install lz4 development library Source: https://github.com/genivia/ugrep/blob/master/README.md Install the lz4 development library using apt-get for searching .lz4 files in ugrep. ```bash sudo apt-get install -y liblz4-dev ``` -------------------------------- ### Basic search with file name globbing Source: https://github.com/genivia/ugrep/blob/master/README.md This example demonstrates a basic search for 'xyz' in files starting with 'foo' in the current directory. The '-s' option suppresses warnings and '-l' lists only filenames. ```bash ug -sl 'xyz' foo* ``` -------------------------------- ### Install ugrep with Winget on Windows Source: https://github.com/genivia/ugrep/blob/master/README.md Install ugrep on Windows using the Windows Package Manager (Winget). ```powershell winget install Genivia.ugrep ``` -------------------------------- ### Install PCRE2 development library Source: https://github.com/genivia/ugrep/blob/master/README.md Install the PCRE2 development library using apt-get for Perl regular expression support in ugrep. ```bash sudo apt-get install -y libpcre2-dev ``` -------------------------------- ### Install ugrep with Chocolatey on Windows Source: https://github.com/genivia/ugrep/blob/master/README.md Install ugrep on Windows using the Chocolatey package manager. ```powershell choco install ugrep ``` -------------------------------- ### Interactive Search with Initial Pattern and Context Source: https://github.com/genivia/ugrep/blob/master/README.md Search 'main.cpp' interactively, starting with the pattern 'TODO' and setting an initial match context of 5 lines. This overrides the default context. ```bash ug -Q -C5 -e TODO main.cpp ``` -------------------------------- ### Install ugrep on Debian Source: https://github.com/genivia/ugrep/blob/master/README.md Install ugrep on Debian using the apt-get package manager. ```bash $ apt-get install ugrep ``` -------------------------------- ### Install ugrep with Homebrew on macOS Source: https://github.com/genivia/ugrep/blob/master/README.md Use Homebrew to install the latest version of ugrep on macOS. This command installs both `ugrep` and `ug` executables. ```bash $ brew install ugrep ``` -------------------------------- ### Install ugrep on CentOS Source: https://github.com/genivia/ugrep/blob/master/README.md Install ugrep on CentOS after enabling the EPEL repository. Uses dnf package manager. ```bash $ dnf install ugrep ``` -------------------------------- ### Install ugrep on Arch Linux Source: https://github.com/genivia/ugrep/blob/master/README.md Install ugrep on Arch Linux using the pacman package manager. ```bash $ pacman -S ugrep ``` -------------------------------- ### Find text blocks between BEGIN and END markers Source: https://github.com/genivia/ugrep/blob/master/README.md This example uses a regex with a lazy quantifier (*?) to find blocks of text between lines starting with 'BEGIN' and 'END'. It matches newlines using `\n` and captures multi-line content. ```bash $ ugrep -n 'BEGIN.*\n(.*\n)*?.*END' myfile.txt ``` -------------------------------- ### Output Matches in XML Format Source: https://github.com/genivia/ugrep/blob/master/README.md The --xml option formats output as XML. This example searches for 'TODO' and includes line and column numbers as attributes. ```bash ug -tc++ -nk --xml 'TODO' ``` -------------------------------- ### Build Boost Regex Libraries (64-bit) Source: https://github.com/genivia/ugrep/blob/master/msvc/README.md Builds the 64-bit static Boost regex libraries using the b2 tool. Ensure the toolset version matches your Visual Studio installation. ```bash b2 -a toolset=msvc-14.2 address-model=64 architecture=x86 runtime-link=static variant=release link=static threading=multi --with-regex ``` -------------------------------- ### Recursive search with immediate subdirectory inclusion Source: https://github.com/genivia/ugrep/blob/master/README.md This example shows how to recursively search for 'xyz' and include files only from immediate subdirectories that match '/foo*/'. This is equivalent to using --include-dir='/foo*'. ```bash ug -rl 'xyz' -g'/foo*/' ``` -------------------------------- ### Search after the first line Source: https://github.com/genivia/ugrep/blob/master/README.md Use -K2 to start searching from the second line of the file. -n displays line numbers. ```bash ug -n -K2 -w make install.sh ``` -------------------------------- ### Build Boost Regex Libraries (32-bit) Source: https://github.com/genivia/ugrep/blob/master/msvc/README.md Builds the 32-bit static Boost regex libraries using the b2 tool. Ensure the toolset version matches your Visual Studio installation. ```bash b2 -a toolset=msvc-14.2 address-model=32 architecture=x86 runtime-link=static variant=release link=static threading=multi --with-regex ``` -------------------------------- ### Interactive TUI Search for 'main' Source: https://github.com/genivia/ugrep/blob/master/README.md Starts the interactive query TUI with 'main' as the initial search pattern. Requires the -e option because command-line arguments are treated as files/directories when -Q is used. ```bash ug -Q -tc++ -e main ``` -------------------------------- ### Display one line of context before C function definitions Source: https://github.com/genivia/ugrep/blob/master/README.md Use the -B option to show lines preceding a match. This example specifically targets C function definitions and displays one preceding line. ```bash ug -B1 -f c/functions myfile.c ``` -------------------------------- ### List Files by Shebang Signature Source: https://github.com/genivia/ugrep/blob/master/README.md Recursively list all files that start with `#!` shebangs using the `-M` option to match file magic bytes. ```bash ug -l -M'#!' '' ``` -------------------------------- ### Basic Custom Output Format Source: https://github.com/genivia/ugrep/blob/master/README.md Use the --format option to specify a custom output format. For example, to output matching lines with filename and line number, use '%f:%n:%O%~'. ```bash --format='%f:%n:%O%~' ``` -------------------------------- ### List non-empty files up to two levels deep Source: https://github.com/genivia/ugrep/blob/master/README.md Use the --depth option (e.g., -2) to limit the recursion depth. This example searches the specified directory and its immediate subdirectories. ```bash ug -2 -l '' mydir ``` -------------------------------- ### Search non-binary files with -a Source: https://github.com/genivia/ugrep/blob/master/README.md Disable binary content checking and speed up searches in non-binary files by using the -a (--text) option. This example searches for 'int' in C++ source files. ```bash ug -r -a -Ocpp -w 'int' ``` -------------------------------- ### Display Unicode Character Range with \x{hhhh} Source: https://github.com/genivia/ugrep/blob/master/README.md Achieves the same result as the previous example by using the \x{hhhh} syntax to specify a Unicode character range for matching. ```bash ug '[\x{1F600}-\x{1F60F}]' emojis.txt ``` -------------------------------- ### Display line and column numbers with context for 'FIXME' in Javascript files Source: https://github.com/genivia/ugrep/blob/master/README.md Similar to the C++ example, this searches recursively (-R) for 'FIXME' in Javascript files (-tjs), showing line and column numbers (-n -k). It uses -C20 to show up to 20 characters of context before and after, and -o to extract only matches. ```bash $ ugrep -o -C20 -R -n -k -tjs FIXME ``` -------------------------------- ### Display one line of context before C++ function definitions Source: https://github.com/genivia/ugrep/blob/master/README.md Similar to the C function example, this uses -B1 to show preceding context for C++ function definitions, which may include Unicode characters. ```bash ug -B1 -f c++/functions myfile.cpp ``` -------------------------------- ### List lines with 'amount' and a decimal number Source: https://github.com/genivia/ugrep/blob/master/README.md This example uses a regular expression to find lines containing 'amount' followed by a decimal number. The space acts as an AND operator. Requires -% for extended regex. ```bash $ ugrep -i -% 'amount \d+(\.\d+)?' myfile.txt ``` -------------------------------- ### Output Matches in CSV Format Source: https://github.com/genivia/ugrep/blob/master/README.md Use the --csv option to output search results in CSV format. This example includes file pathname, line number, and column number fields. ```bash ug -tc++ --csv -Hnk 'TODO' ``` -------------------------------- ### Recursive search for specific file extension using path matching Source: https://github.com/genivia/ugrep/blob/master/README.md This example demonstrates a recursive search for 'xyz' where the glob pattern '**/*.cpp' matches '.cpp' files anywhere in the directory structure. This differs from '*.cpp' by explicitly matching path components. ```bash ug -rl 'xyz' -g'**/*.cpp' ``` -------------------------------- ### List non-empty files recursively, not following symbolic links Source: https://github.com/genivia/ugrep/blob/master/README.md Combine -r and -l to recursively list files. By default, -r follows symbolic links only if they are on the command line; this example explicitly shows not following them. ```bash ug -rl '' mydir ``` -------------------------------- ### Fuzzy Search with TUI and Boolean Logic Source: https://github.com/genivia/ugrep/blob/master/README.md Combines Fzf-like interactive search with fuzzy matching, Boolean logic, and sorting. This example searches for words only, allowing up to 4 extra characters in fuzzy matches, and sorts results by relevance. ```bash ug -Q -%% -l -w -Z+4 --sort=best ``` -------------------------------- ### Use Predefined Patterns for Includes and Defines Source: https://github.com/genivia/ugrep/blob/master/README.md Search C++ files for '#include' and '#define' directives using predefined patterns. The --pretty option enhances output readability. ```bash ug --pretty -r -n -tc++ -f c++/includes -f c++/defines ``` -------------------------------- ### Show General Help Source: https://github.com/genivia/ugrep/blob/master/README.md Display a general help message for the ug command, outlining basic usage and common options. ```bash ug --help ``` -------------------------------- ### List Files by Shebang Signature (Excluding Specific) Source: https://github.com/genivia/ugrep/blob/master/README.md Recursively list files starting with `#` but exclude those that start with `#!`. ```bash ug -l -M'#' -M'^#!' '' ``` -------------------------------- ### Open Interactive Query TUI with Help Source: https://github.com/genivia/ugrep/blob/master/README.md Launch the interactive query TUI (Text User Interface) and immediately display the help screen. Press F1 or CTRL-Z within the TUI to access help and options. ```bash ug -Q ``` -------------------------------- ### Install ugrep with MacPorts on macOS Source: https://github.com/genivia/ugrep/blob/master/README.md Use MacPorts to install ugrep on macOS. This command requires sudo privileges. ```bash $ sudo port install ugrep ``` -------------------------------- ### Build static executables Source: https://github.com/genivia/ugrep/blob/master/README.md Use the --enable-static flag to attempt building static executables. This may require additional flags like --without-brotli if certain libraries do not link statically. ```bash $ ./build.sh --enable-static ``` ```bash $ ./build.sh --enable-static --without-brotli ``` -------------------------------- ### Build liblzma for x32 and x64 Source: https://github.com/genivia/ugrep/blob/master/vs/ugrep/README.txt Build the liblzma library for both Win32 and x64 ReleaseMT configurations using Visual Studio 2017. The resulting .lib files are then copied to the project directory. ```batch Change dir to xz-5.2.4/windows/vs2017. Open xz_win.sln to open Visual Studio 2017. Select ReleaseMT/Win32 and then build solution liblzma. Copy ReleaseMT\Win32\liblzma.lib to liblzma-x32.lib here (in the directory of this README). Select ReleaseMT/x64 and then build solution liblzma. Copy ReleaseMT\x64\liblzma.lib to liblzma-x64.lib here (in the directory of this README). ``` -------------------------------- ### Show Help for Specific Options Source: https://github.com/genivia/ugrep/blob/master/README.md Filter the help output to show only options related to a specific keyword, such as 'WHAT'. This is useful for quickly finding relevant commands. ```bash ug --help WHAT ``` -------------------------------- ### Case-Insensitive Search in UTF-16 File with BOM Source: https://github.com/genivia/ugrep/blob/master/README.md Performs a case-insensitive search for 'lorem' in a UTF-16 file that starts with a UTF-16 BOM. ```bash ug -iw 'lorem' utf16lorem.txt ``` -------------------------------- ### Advanced formatting with --format Source: https://github.com/genivia/ugrep/blob/master/README.md Display matching lines with line and column numbers, and the matching part only. The format string uses placeholders like %n for line number, %k for column, %o for the match, and %~ for a newline. ```bash ug -r --format='%n,%k:%o%~' '\w+' ``` -------------------------------- ### Load Named Configuration File Source: https://github.com/genivia/ugrep/blob/master/README.md Use the `---FILE` option (shorthand for `--config=FILE`) to load a specific configuration file. This allows for streamlined custom search tasks by predefining a set of options in `FILE`. ```bash ug ---FILE PATTERN ... ``` ```bash ugrep ---FILE PATTERN ... ``` -------------------------------- ### Get Archive Part Info Source: https://github.com/genivia/ugrep/blob/master/lzma/C/README.txt Retrieves the pathname, modification time, and uncompressed size of an archive part. This function should be called before decompressing. ```c int viiget(struct viizip *viizip, char *name, size_t max, time_t *mtime, uint64_t *usize) ``` -------------------------------- ### Specify pattern with -e Source: https://github.com/genivia/ugrep/blob/master/README.md Use the -e option to explicitly specify a pattern, preventing it from being interpreted as a command-line option. This example searches for '-o' in script.sh. ```bash ug -n -e '-o' script.sh ``` -------------------------------- ### Build ugrep executable Source: https://github.com/genivia/ugrep/blob/master/README.md Execute the build script to compile ugrep. This process includes configuration, compilation, and testing. ```bash $ cd ugrep $ ./build.sh ``` -------------------------------- ### Include hidden files with --ignore-files Source: https://github.com/genivia/ugrep/blob/master/README.md This command searches recursively and ignores .gitignore rules, but it also includes hidden files (those starting with '.') in the search results. ```bash ug -rl. --ignore-files 'xyz' ``` -------------------------------- ### Interactive fuzzy search with sorting Source: https://github.com/genivia/ugrep/blob/master/README.md Use -Q for interactive fuzzy search. -l lists files, -% uses Boolean queries, -Z2 sets fuzzy matching level, and --sort=best sorts by relevance. ```bash $ ugrep -Q -l -% -Z2 --sort=best ``` -------------------------------- ### Find C/C++ function definitions using predefined patterns and pipes Source: https://github.com/genivia/ugrep/blob/master/README.md Select C/C++ function definitions using `-Oc,cpp` and the `c/functions` predefined pattern, then pipe the output to search for a specific function like `qsort`. ```bash ug -R -Oc,cpp -nk -f c/functions | ug 'qsort' ``` -------------------------------- ### Override Colors with Pretty Output Source: https://github.com/genivia/ugrep/blob/master/README.md Customize the color scheme when using --pretty output. This example sets inverted yellow for matches and yellow-on-blue for headings. ```bash ug --pretty --colors="ms=yi:fn=hyB" -r -n -tc++ -f c++/includes -f c++/defines ``` -------------------------------- ### Character Class Examples Source: https://github.com/genivia/ugrep/blob/master/README.md Illustrates various character class operations like negation, subtraction, intersection, and union. Note that negated character classes do not match newlines. ```regex [a-zA-Z] ``` ```regex [^a-zA-Z] ``` ```regex [a-z−−[aeiou]] ``` ```regex [a-z&&[^aeiou]] ``` ```regex [a-z⎮⎮[A-Z]] ``` -------------------------------- ### Create 7zip Decompressor Source: https://github.com/genivia/ugrep/blob/master/lzma/C/README.txt Initializes a new 7zip decompressor for a given file. Ensure the FILE pointer is valid. ```c struct viizip *viinew(FILE *file) ``` -------------------------------- ### Specify pattern with -- Source: https://github.com/genivia/ugrep/blob/master/README.md Alternatively, use '--' to signify the end of command-line arguments, ensuring subsequent arguments are treated as patterns. This example searches for '-o' in script.sh. ```bash ug -n -- '-o' script.sh ``` -------------------------------- ### Configure Release x86 Project Properties Source: https://github.com/genivia/ugrep/blob/master/vs/ugrep/README.txt Set the project configuration properties for Release x86 to ensure correct build settings. This includes general, C/C++ preprocessor definitions, and linker inputs. ```properties Project Configuration Properties General: Use of MFC: Use Standard Windows Libraries C/C++ General: Additional Include Directories: $(ProjectDir)\include;$(ProjectDir)\..\pcre2-10.42\src;$(ProjectDir)\..\zlib-1.2.11;$(ProjectDir)\..\bzip2-1.0.5;$(ProjectDir)\..\api;$(ProjectDir)\..\lz4-dev\lib;$(ProjectDir)\..\zstd-dev\lib;$(ProjectDir)\lzma\C Preprocessor: Preprocessor Definitions: WIN32;NDEBUG;_CONSOLE;WITH_NO_INDENT;WITH_NO_CODEGEN;HAVE_AVX2;HAVE_PCRE2;PCRE2_STATIC;HAVE_LIBZ;HAVE_LIBBZ2;HAVE_LIBLZMA;HAVE_LIBLZ4;HAVE_LIBZSTD;WITH_COLOR;ZLIB_WINAPI;NO_GZCOMPRESS;LZMA_API_STATIC;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS Code Generation: Runtime Library: Multi-threaded (/MT) Precompiled Headers: Precompiled Header: Not Using Precompiled Headers Linker: General: Additional Library Directories: $(ProjectDir)\..;$(ProjectDir)\..\zstd-dev\build\VS2010\bin\Win32_Release Input: Additional Dependencies: pcre2-x32.lib;liblzma-x32.lib;libzstd_static.lib;viiz-x32.lib Manifest Tool: Input and Output: Additional Manifest Files: $(ProjectDir)\..\manifest.xml ``` -------------------------------- ### Search Tarballs for PDF Files Source: https://github.com/genivia/ugrep/blob/master/README.md Iterate through tar archives and use ugrep to find files ending with '.pdf' within each archive. This example assumes a bash shell. ```bash for tb in *.tar *.tar.gz *.tgz; do echo "$tb"; tar tfz "$tb" | ugrep '.*\.pdf$'; done ``` -------------------------------- ### Pretty output with context and match details Source: https://github.com/genivia/ugrep/blob/master/README.md Use --pretty with -o and context options for enhanced output, including headings, line numbers, and column numbers (-k). This provides a more readable format for matches and their context. ```bash ug --pretty -oC20 'pattern' myfile.cpp ``` -------------------------------- ### Set GREP_COLORS for Alternative Color Scheme Source: https://github.com/genivia/ugrep/blob/master/README.md Apply an alternative color scheme by adjusting the GREP_COLORS environment variable. This example uses a combination of intensity and color codes. ```bash export GREP_COLORS='cx=hb:ms=hiy:mc=hic:fn=hi+y+K:ln=hg:cn=hg:bn=hg:se=' ``` -------------------------------- ### Search 'myproject' at One Level Source: https://github.com/genivia/ugrep/blob/master/README.md Searches for the whole word 'main' within the 'myproject' directory at the top level only. Directory arguments are searched at one level by default. ```bash ug -nkw main myproject ``` -------------------------------- ### Speed up searches with -u Source: https://github.com/genivia/ugrep/blob/master/README.md When each match occurs on a single line, use the -u (--ungroup) option to potentially speed up searches. This example searches for 'def' in Python files. ```bash ug -r -a -u -Opython -w 'def' ``` -------------------------------- ### Enable AVX512 and Add Preprocessor Definition Source: https://github.com/genivia/ugrep/blob/master/vs/ugrep/README.txt To enable AVX512, right-click on the matcher_avx512bw.cpp file, set the 'Enable Enhanced Instruction Set' to 'Advanced Vector Extensions 512', and add 'HAVE_AVX512BW' to the preprocessor definitions. ```properties C/C++ Preprocessor: Preprocessor Definitions: WIN32;NDEBUG;_CONSOLE;WITH_NO_INDENT;WITH_NO_CODEGEN;HAVE_AVX2;HAVE_AVX512BW;HAVE_BOOST_REGEX;HAVE_LIBZ;HAVE_LIBBZ2;HAVE_LIBLZMA;HAVE_LIBLZ4;HAVE_LIBZSTD;WITH_COLOR;ZLIB_WINAPI;NO_GZCOMPRESS;LZMA_API_STATIC;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_WARNINGS Code Generation: Enable Enhanced Instruction Set: Advanced Vector Extensions 512 (/arch:AVX512) ``` -------------------------------- ### Recursively list Makefiles matching 'CPP' Source: https://github.com/genivia/ugrep/blob/master/README.md Use -r for recursive search and -g to specify a glob pattern for filenames. This example searches for 'Makefile' files containing 'CPP'. ```bash ug -r -g Makefile 'CPP' ``` -------------------------------- ### List Makefile.* files matching 'bin_PROGRAMS' Source: https://github.com/genivia/ugrep/blob/master/README.md Recursively lists files matching the glob pattern 'Makefile.*' and containing the string 'bin_PROGRAMS'. Useful for finding build-related files. ```bash ug -l -g'Makefile.*' 'bin_PROGRAMS' ``` -------------------------------- ### Build Boost.Regex Static Libraries Source: https://github.com/genivia/ugrep/blob/master/vs/ugrep/README.txt Build Boost.Regex as a static release library with static runtime linkage using the b2 command. This is required for using Boost.Regex with ugrep. ```bash bootstrap vc141 b2 -a toolset=msvc-14.1 address-model=32 architecture=x86 runtime-link=static variant=release link=static threading=multi --with-regex b2 -a toolset=msvc-14.1 address-model=64 architecture=x86 runtime-link=static variant=release link=static threading=multi --with-regex ``` -------------------------------- ### List non-empty files recursively, following symbolic links Source: https://github.com/genivia/ugrep/blob/master/README.md Use -R to recursively search directories and follow all symbolic links, including those to directories. ```bash ug -R -l '' mydir ``` -------------------------------- ### Set GREP_COLORS for Windows Command Interpreter Source: https://github.com/genivia/ugrep/blob/master/README.md Configure GREP_COLORS on Windows using the SET command. This example sets specific colors for various elements like selected lines and matches. ```cmd SET GREP_COLORS=sl=1;37:cx=33:mt=1;31:fn=1;35:ln=1;32:cn=1;32:bn=1;32:se=36 ``` -------------------------------- ### Implicitly exclude files using a symlink Source: https://github.com/genivia/ugrep/blob/master/README.md This example demonstrates how to make exclusions from '.git/info/exclude' implicit by creating a symlink named '.ignore' to it. Then, 'ug --ignore-files=.ignore' uses this symlink for exclusions. ```bash ln -s .git/info/exclude .ignore ug -rl '' --ignore-files --ignore-files=.ignore ``` -------------------------------- ### Display ugrep Man Page Source: https://github.com/genivia/ugrep/blob/master/README.md Access the complete manual page for ugrep to understand all available options and functionalities. ```bash man ugrep ``` -------------------------------- ### viiz Library Preprocessor Definitions for ugrep Source: https://github.com/genivia/ugrep/blob/master/vs/ugrep/README.txt These preprocessor definitions are necessary for building the viiz library, which is based on the 7zip LZMA SDK. Key definitions include WIN32, NDEBUG, _LIB, WIN32_LEAN_AND_MEAN, Z7_PPMD_SUPPORT, Z7_EXTRACT_ONLY, _REENTRANT, _FILE_OFFSET_BITS=64, and _LARGEFILE_SOURCE. ```text WIN32;NDEBUG;_LIB;WIN32_LEAN_AND_MEAN;Z7_PPMD_SUPPORT;Z7_EXTRACT_ONLY;_REENTRANT;_FILE_OFFSET_BITS=64;_LARGEFILE_SOURCE ``` -------------------------------- ### Search Hidden Files Recursively Source: https://github.com/genivia/ugrep/blob/master/README.md Use the --hidden or -. option to include hidden files and directories in recursive searches. This example searches for 'login' in shell scripts within the working directory. ```bash ug -. -tShell 'login' ``` -------------------------------- ### Output Results in Different Formats Source: https://github.com/genivia/ugrep/blob/master/README.md Use --csv, --json, or --xml to output results in structured formats. --format allows user-specified output formats using % fields. ```bash ug --csv PATTERN ... ug --json PATTERN ... ug --xml PATTERN ... ``` ```bash ug --format='file=%f line=%n match=%O%~' PATTERN ... ``` -------------------------------- ### Configure LD_LIBRARY_PATH Source: https://github.com/genivia/ugrep/blob/master/README.md Add ugrep's local library path to LD_LIBRARY_PATH in ~/.bashrc to resolve library load errors on some Linux systems. ```bash export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/local/lib" ``` -------------------------------- ### Enable AVX2 Instruction Set Source: https://github.com/genivia/ugrep/blob/master/vs/ugrep/README.txt To enable AVX2, right-click on the matcher_avx2.cpp file and configure the 'Enable Enhanced Instruction Set' option in the project properties. ```properties C/C++ Code Generation: Enable Enhanced Instruction Set: Advanced Vector Extensions 2 (/arch:AVX2) ``` -------------------------------- ### Set GREP_COLORS for Color Highlighting (Numeric Codes) Source: https://github.com/genivia/ugrep/blob/master/README.md Configure GREP_COLORS using standard ANSI escape codes for detailed color control. This example sets specific styles for selected lines, matches, and file names. ```bash export GREP_COLORS='sl=1:cx=33:ms=1;4;32;100:mc=1;4;32:fn=1;32;100:ln=1;32:cn=1;32:bn=1;32:se=36' ``` -------------------------------- ### Search text files with cat -v filter Source: https://github.com/genivia/ugrep/blob/master/README.md Recursively search .txt and .md files for 'eat me', converting non-printable characters using 'cat -v'. This example shows specifying multiple file extensions for a single filter. ```bash ug -r -ttext --filter='txt,md:cat -v' 'eat me' ``` -------------------------------- ### Build Ugrep with ThreadSanitizer Source: https://github.com/genivia/ugrep/blob/master/README.md Use this command to build ugrep with the ThreadSanitizer enabled for detecting data races. This incurs significant runtime overhead and is not recommended for final builds. ```bash ./build.sh CXXFLAGS='-fsanitize=thread -O1 -g' ``` -------------------------------- ### Search 'myproject' Two Levels Deep Source: https://github.com/genivia/ugrep/blob/master/README.md Searches for the whole word 'main' within 'myproject' and one subdirectory level deeper (two levels total). ```bash ug -2 -nkw main myproject ``` -------------------------------- ### Recursive search including nested subdirectories Source: https://github.com/genivia/ugrep/blob/master/README.md This example searches for 'xyz' recursively, including files only in paths that contain a 'doc' directory followed by an 'html' directory anywhere within the path. The pattern 'doc/**/html/' enables this deep matching. ```bash ug -rl 'xyz' -g'doc/**/html/' ``` -------------------------------- ### Select Files from Archive for Decompression Source: https://github.com/genivia/ugrep/blob/master/README.md Use ugrep's query selection mode to select files from 'project.zip' for decompression with 'unzip'. Press Enter to select lines. ```bash unzip project.zip `zipinfo -1 project.zip | ugrep -Q` ``` -------------------------------- ### Display two lines of context around matches Source: https://github.com/genivia/ugrep/blob/master/README.md Use the -C option to display a specified number of lines before and after each matching line. This is useful for understanding the context of a match. ```bash ug -C2 'FIXME' myfile.cpp ``` -------------------------------- ### Search for 'main' with Line and Column Numbers Source: https://github.com/genivia/ugrep/blob/master/README.md Recursively searches for the whole word 'main' in the 'myproject' directory without following symlinks. Displays matching line and column numbers. ```bash ug -r -nkw main myproject ``` -------------------------------- ### Display three lines of context after matches Source: https://github.com/genivia/ugrep/blob/master/README.md The -A option displays a specified number of lines following each match. This is helpful for seeing what comes after a matched pattern. ```bash ug -A3 'FIXME.*' myfile.cpp: ``` -------------------------------- ### Recursive search excluding specific words Source: https://github.com/genivia/ugrep/blob/master/README.md Combine recursive listing (-R), file type filtering (-t), word matching (-w), and pattern exclusion using files (-f) for comprehensive searches. This example finds Python files that do not contain the word 'display', while allowing 'display' within strings and comments. ```bash ug -RL -tPython -w 'display' -f python/zap_strings -f python/zap_comments ``` -------------------------------- ### Search with Color Highlighting and Context Source: https://github.com/genivia/ugrep/blob/master/README.md Perform a recursive search for 'FIXME' and display color-highlighted results with context lines. The --color option is redundant as it's the default. ```bash ug --color -r -n -k -tc++ 'FIXME.*' ``` -------------------------------- ### Fuzzy Interactive Search with ugrep Source: https://github.com/genivia/ugrep/blob/master/README.md Use this command for fzf-like interactive querying with fuzzy matching. Press TAB and ALT-y to view a file with matches, or SHIFT-TAB and ALT-l to return to the list of matching files. ```bash ug -Q -%% -l -w -F -Z+4 --sort=best ```