Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

jftuga/wrapline

Repository files navigation

wrapline

A command-line tool that wraps each line of input with a specified delimiter. Useful for formatting text data, preparing strings for code, or processing structured data.

Features

  • Wrap lines with any delimiter (default: double-quote)
  • Support for hexadecimal delimiter notation
  • Strip whitespace before wrapping
  • Skip empty lines
  • Escape delimiter characters within lines
  • Read from files or STDIN (auto-detects piped input - - is optional when reading from a pipe)
  • Write to files or STDOUT
  • Process null-terminated input (compatible with find -print0, xargs -0)
  • Automatically skip empty last lines

Installation

Build from source

git clone https://github.com/jftuga/wrapline
cd wrapline
make

This creates the wrapline executable in the current directory.

Usage

wrapline [options] <filename|->

Options

  • -d <delimiter> - Delimiter to wrap lines with (default: ")
    • Supports literal strings: -d "|"
    • Supports hex notation: -d 0x27 for single quote
  • -s - Strip whitespace from lines before wrapping
  • -e - Do not emit empty lines
  • -escape - Escape delimiter characters within lines using backslash
  • -o <file> - Write output to file instead of STDOUT
  • -0 - Read null-terminated records instead of newlines
  • -v - Show version and exit

Input

  • Provide a filename to read from a file
  • Use - to read from STDIN
  • When data is piped into wrapline, reading from STDIN is assumed automatically — the - argument is optional

Examples

Basic usage

Wrap lines with double quotes (default):

wrapline input.txt

Input:

hello
world

Output:

"hello"
"world"

Custom delimiter

Wrap lines with single quotes:

wrapline -d "'" input.txt

Output:

'hello'
'world'

Hexadecimal delimiters

Use hexadecimal notation for delimiters (useful for special characters):

# Pipe character (0x7C = ASCII 124)
wrapline -d 0x7C input.txt

# Tab character (0x09)
wrapline -d 0x09 input.txt

Strip whitespace

Remove leading and trailing whitespace before wrapping:

wrapline -s input.txt

Input:

  hello
   world

Output:

"hello"
"world"

Skip empty lines

Don't output empty lines:

wrapline -e input.txt

Input:

hello

world

Output:

"hello"
"world"

Escape delimiters

Escape delimiter characters found within lines:

wrapline -escape input.txt

Input:

She said "hello" to me

Output:

"She said \"hello\" to me"

Output to file

Write results to a file instead of STDOUT:

wrapline -d "|" input.txt -o output.txt

Read from STDIN

wrapline automatically reads from piped input, so the - argument is optional:

echo "hello world" | wrapline
cat input.txt | wrapline -d "'" -s

You can still use - explicitly if preferred:

echo "hello world" | wrapline -

Null-terminated input

Process null-terminated records (like find -print0):

find . -name "*.txt" -print0 | wrapline -0 -

This is useful when filenames may contain newlines or special characters.

Combining options

Combine multiple options for complex processing:

# Strip whitespace, skip empty lines, escape quotes, write to file
wrapline -s -e -escape -o output.txt input.txt

# Process null-terminated, custom delimiter, output to file
find . -type f -print0 | wrapline -0 -d "'" -o filelist.txt -

Create a single-line, comma-delimited list

wrapline can be used in conjunction with paste to produce a CSV-style list:

seq 1 10 | wrapline | paste -sd, -

"1","2","3","4","5","6","7","8","9","10"

Common Use Cases

Prepare strings for code

Convert a list of values into quoted strings for code:

wrapline cities.txt

Input:

New York
Los Angeles
Chicago

Output:

"New York"
"Los Angeles"
"Chicago"

Create CSV-ready data

Wrap fields with quotes:

wrapline -escape data.txt

Format file lists

Process files found by find:

find /var/log -name "*.log" -print0 | wrapline -0 -d "'" -

Clean up text data

Strip whitespace and remove empty lines:

wrapline -s -e messy_data.txt -o clean_data.txt

Notes

  • Empty lines at the end of input are always skipped, regardless of flags
  • When using -e, all empty lines are skipped
  • The -s flag strips whitespace before checking if a line is empty
  • Hexadecimal delimiter values must be prefixed with 0x
  • Without the 0x prefix, numeric strings are treated as literal delimiters
  • wrapline automatically detects piped input and does not require - when reading from a pipe

About

CLI tool that wraps each line of input with a specified delimiter

Topics

Resources

License

Stars

Watchers

Forks