Skip to content
shellhacks.dev
Tooling

Add Prefix or Suffix to Lines

Add a prefix and a suffix to every line of text, with optional line numbers, a {n} placeholder for the line number and empty lines left alone.

Free · No sign-up · Your inputs stay in your browser

Input

Add a prefix or suffix to every line

Output

Result

89 characters

The shell versions: sed 's/^/prefix/' adds a prefix and sed 's/$/suffix/' a suffix, and awk '{print "prefix" $0 "suffix"}' does both. Turning a list of hosts into commands this way is quick; for anything you will run twice, a loop in a script is easier to review.

Runs in this browser. Nothing you paste is sent to a server.

Turning lists into commands

A list of hosts becomes ssh commands, a list of files becomes chmod lines, a list of ids becomes SQL values, a block of text becomes a quote or commented-out code. For anything you will run more than once, a loop in a script is easier to review than generated commands.

The shell equivalents

sed 's/^/PREFIX/' adds a prefix and sed 's/$/SUFFIX/' a suffix; awk can do both in one pass and use NR for the line number.

Share

Frequently asked questions

How do I number lines?
Turn on Number the lines, or put {n} where the number should go, such as {n}) or line {n}:.
Can I comment out code this way?
Yes: prefix with # or // and a space. Editors' toggle comment shortcut does the same inside a file.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Go deeper

Suggested reading

Keep planning

Similar tools