To add a prefix to all lines in a file on Linux, you don’t need to open a terminal or remember sed syntax. The Add Prefix and Suffix to Lines tool lets you paste the file contents, enter the prefix, and generate the updated text in seconds—all in your browser, with no uploads or installations. This method works for any text file, whether it’s a list of hostnames, a configuration snippet, or a CSV export. You can also add a suffix at the same time, and choose whether to skip blank lines or decorate them too. The tool outputs a clean UTF-8 TXT file you can download or copy straight back into your Linux environment.

Linux users often reach for command-line tools like sed, awk, or even a quick for loop to add prefixes to lines. While these work, they require remembering the exact syntax, escaping special characters, and sometimes handling line endings differently across systems. For example, sed on macOS and GNU sed on Linux treat the -i flag differently, which can trip up scripts. If you’re working with a one-off file or a small set of lines, firing up a terminal just to add “https://” to every URL feels like overkill. A browser-based tool removes that friction: paste, type, generate, and you’re done. It’s especially useful when you’re already in a graphical environment, like editing a config file in VS Code or reviewing a log in a web interface.

add prefix to all lines in file linux
add prefix to all lines in file linux

When to Use a Browser Tool Instead of the Command Line

There are several scenarios where using a browser tool to add prefixes to lines makes more sense than the command line:

Scenario Command-Line Approach Browser-Tool Approach
One-off task with a small file Open terminal, type sed command, verify output Paste text, enter prefix, download result
Working on a system without sed/awk Install coreutils or find an alternative Open browser, use the tool instantly
Need to preview changes before saving Pipe to less or redirect to a temp file See the result in real time before downloading
Handling special characters in prefix Escape quotes, slashes, and other symbols Type the prefix as-is, no escaping needed
Collaborating with non-technical users Explain sed syntax or write a script for them Send a link to the tool—no instructions needed

For bulk operations on large files or automation in scripts, command-line tools are still the best choice. But for quick, one-time edits—especially when you’re already in a GUI—using a browser tool like Add Prefix and Suffix to Lines is faster and less error-prone.

How to Add a Prefix to Every Line in a File Without the Command Line

Here’s how to use the Add Prefix and Suffix to Lines tool to add a prefix to all lines in your file:

  1. Open the Add Prefix and Suffix to Lines tool in your browser.
  2. Paste the contents of your file into the input box. You can also type the lines manually if you prefer.
  3. In the “Prefix” field, enter the text you want to add to the start of every line (e.g., “https://” or “- ”).
  4. (Optional) If you also want to add a suffix, enter it in the “Suffix” field.
  5. Choose whether to leave blank lines untouched or apply the prefix/suffix to them as well. The default is to skip blank lines.
  6. Click “Generate” to see the result in the preview box.
  7. Review the output to make sure it looks correct. The tool preserves your original line endings and encoding.
  8. Click “Download” to save the result as a UTF-8 TXT file, or copy the text and paste it back into your original file.

Common Use Cases for Adding Prefixes to Lines

Adding a prefix to every line in a file is a common task in Linux environments. Here are some practical examples where this comes in handy:

  • URLs and links: Add “https://” to a list of domains to turn them into clickable links. This is useful when migrating a list of hostnames to a web server configuration or a spreadsheet.
  • Command-line arguments: Prefix every line with “--option=” to turn a list of values into command-line flags for a script or CLI tool.
  • Code snippets: Add a comment character like “#” or “//” to every line to quickly comment out a block of code or configuration.
  • CSV or TSV data: Add a column name or identifier to the start of every line to prepare the data for import into a database or spreadsheet.
  • Log files: Prefix each line with a timestamp or hostname to correlate entries from multiple sources.
  • Markdown lists: Add “- ” or “* ” to every line to turn a plain list into a bulleted list for documentation or a README file.
  • Configuration files: Add a path prefix like “/var/www/” to a list of filenames to create absolute paths for a web server or application.

In each of these cases, the Add Prefix and Suffix to Lines tool lets you apply the prefix without touching the command line. For example, if you’re working with a list of domains in a text file, you can paste them into the tool, add “https://”, and download the result—no sed, awk, or escaping required. The tool also handles edge cases like blank lines, so you don’t have to worry about accidentally decorating empty lines unless you want to.

How the Tool Handles Line Endings and Encoding

The Add Prefix and Suffix to Lines tool preserves the original line endings and encoding of your text, which is important when working with files on Linux. Linux, Windows, and macOS use different line-ending conventions:

  • Linux/macOS (Unix): Uses LF (line feed, \n) as the line ending.
  • Windows: Uses CRLF (carriage return + line feed, \r\n) as the line ending.
  • Older macOS: Used CR (carriage return, \r) before switching to LF.

When you paste text into the tool, it detects the line endings in your input and applies the prefix/suffix without altering them. This means if you paste a file with LF line endings, the output will also use LF. The tool also preserves the encoding of your text, outputting a UTF-8 TXT file by default. UTF-8 is the most widely used encoding on Linux and the web, so the output will work seamlessly with other tools and systems.

If you’re working with a file that has mixed line endings (e.g., some lines use CRLF and others use LF), the tool will preserve the original line endings for each line. This is useful when you’re editing a file that was created on Windows and later modified on Linux. For most use cases, though, you won’t need to worry about line endings—the tool handles them automatically.

Alternatives to the Browser Tool for Adding Prefixes

While the Add Prefix and Suffix to Lines tool is the fastest way to add prefixes to lines without the command line, there are other methods you can use on Linux. Here’s how they compare:

Method Pros Cons Best For
sed (command line) Fast, scriptable, works on large files Requires escaping special characters, different syntax across systems Automation, bulk operations, scripting
awk (command line) Flexible, can handle complex patterns Steeper learning curve, more verbose for simple tasks Advanced text processing, conditional logic
Perl (command line) Powerful, handles edge cases well Overkill for simple tasks, less common in modern scripts Legacy scripts, complex transformations
Text editor (e.g., VS Code, Vim) Visual feedback, undo/redo support Manual work, not scriptable, slower for large files One-off edits, interactive workflows
Browser tool (Add Prefix and Suffix to Lines) No installation, no syntax to remember, instant preview Requires a browser, not suitable for automation Quick edits, non-technical users, small to medium files

For example, if you’re already comfortable with the command line, you can use sed to add a prefix to every line in a file like this:

sed -i 's/^/https:\/\//' file.txt

This command adds “https://” to the start of every line in file.txt. The -i flag edits the file in place, and the ^ symbol matches the start of each line. However, if your prefix contains special characters like slashes or quotes, you’ll need to escape them, which can get messy. The browser tool avoids this by letting you type the prefix as-is.

If you’re working with a large file (e.g., 100,000+ lines), command-line tools like sed or awk will be faster than a browser tool. But for most everyday tasks—like adding “- ” to a list of 50 items or prefixing a configuration snippet with “#”—the browser tool is the simplest option. It’s also the only method that doesn’t require any setup or syntax knowledge, making it ideal for non-technical users or quick edits.

How to Automate Adding Prefixes to Lines in Linux

If you frequently need to add prefixes to lines in Linux, you can automate the process using shell scripts or command-line tools. Here are a few ways to do it:

  • Using sed: Create a script that takes a file and a prefix as arguments, then uses sed to add the prefix to every line. For example:
    #!/bin/bash
    # add-prefix.sh
    prefix="$1"
    file="$2"
    sed -i "s/^/$prefix/" "$file"

    Run the script with ./add-prefix.sh "https://" file.txt to add “https://” to every line in file.txt.

  • Using awk: awk is another powerful tool for text processing. Here’s a script that adds a prefix to every line:
    #!/bin/bash
    # add-prefix-awk.sh
    prefix="$1"
    file="$2"
    awk -v p="$prefix" '{print p $0}' "$file" > temp && mv temp "$file"

    Run the script with ./add-prefix-awk.sh "https://" file.txt.

  • Using a for loop: For simple cases, you can use a for loop to read each line, add the prefix, and write the result to a new file:
    #!/bin/bash
    # add-prefix-loop.sh
    prefix="$1"
    file="$2"
    while IFS= read -r line; do
      echo "$prefix$line"
    done < "$file" > temp && mv temp "$file"

    Run the script with ./add-prefix-loop.sh "https://" file.txt.

These scripts are useful for automation, but they require some familiarity with the command line. If you’re not comfortable writing scripts, the Add Prefix and Suffix to Lines tool is a simpler alternative. It’s also more flexible, since you can add both a prefix and a suffix at the same time, and choose whether to skip blank lines.

For example, if you’re working with a list of domains and want to turn them into Markdown links, you can use the tool to add “[” as a prefix and “](https://example.com)” as a suffix. The command-line alternatives would require more complex escaping and syntax, while the browser tool lets you do it in a few clicks.

Tips for Working with Text Files in Linux

Whether you’re using the Add Prefix and Suffix to Lines tool or the command line, here are some tips for working with text files in Linux:

  • Check line endings: Use the file command to check the line endings in a text file. For example, file file.txt will show whether the file uses LF, CRLF, or CR line endings. This is useful when you’re working with files created on different operating systems.
  • Count lines: Use the wc -l command to count the number of lines in a file. For example, wc -l file.txt will output the line count. If you need more detailed statistics, like the number of blank lines or the longest line, you can use the Line Counter tool.
  • Remove blank lines: Use the grep -v '^$' command to remove blank lines from a file. For example, grep -v '^$' file.txt > output.txt will create a new file with no blank lines. If you prefer a browser tool, the Remove Empty Lines tool does the same thing without the command line.
  • Convert line endings: Use the dos2unix or unix2dos commands to convert line endings between Windows and Linux formats. For example, dos2unix file.txt will convert CRLF line endings to LF. If you don’t have these tools installed, you can use the Line Break Converter tool in your browser.
  • Extract email addresses: Use the grep -Eio '\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b' command to extract email addresses from a file. For a simpler approach, use the Email Extractor tool, which also deduplicates and sorts the results.
  • Remove duplicate lines: Use the sort -u command to remove duplicate lines from a file. For example, sort -u file.txt > output.txt will create a new file with no duplicates. If you need more control over the comparison, use the Remove Duplicate Lines tool.

These tips can help you work more efficiently with text files in Linux. if you're using the command line or a browser tool, understanding the basics of line endings, encoding, and text processing will make your workflow smoother.

See also: Change Text Case in Excel Without Formulas or Add-ins.