LinuxCommandLibrary

keep-header

Preserve specific HTTP headers during redirection

TLDR

Sort a file and keep the first line at the top

$ keep-header [path/to/file] -- sort
copy

Output first line directly to stdout, passing the remainder of the file through the specified command
$ keep-header [path/to/file] -- [command]
copy

Read from stdin, sorting all except the first line
$ cat [path/to/file] | keep-header -- [command]
copy

Grep a file, keeping the first line regardless of the search pattern
$ keep-header [path/to/file] -- grep [pattern]
copy

SYNOPSIS

keep-header [header...]

PARAMETERS

header
    The name of a header field to keep. Multiple header fields can be specified. The command will search and output header field, also it will include the body of the message. Header fields are case-insensitive.

DESCRIPTION

The keep-header command is used to extract and display specified headers from mail messages or Usenet news articles. It reads the input from standard input, searches for the requested headers, and prints the headers and the message body to standard output. This is particularly useful for filtering email or news content based on specific header fields, allowing users to focus on relevant information. It is a relatively simple tool primarily used in scripting or as part of larger mail processing pipelines. The main use case is filtering messages and extracting specific headers. The command is useful for automating mail filtering tasks, archiving specific header information, or debugging mail transfer problems.

USAGE EXAMPLES

To extract the "Subject" and "From" headers from an email message piped to keep-header: cat email.txt | keep-header Subject From This will print the Subject and From headers followed by the body of the email.

LIMITATIONS

keep-header is a simple text-processing tool and may not handle complex MIME encoded messages correctly. For more robust mail processing, consider using dedicated mail parsing libraries or mail user agents.

SEE ALSO

grep(1), sed(1), awk(1)

Copied to clipboard