Enhance Your Text Files: Adding Suffixes to Each Line with Shell Scripting

Learn how to efficiently add a suffix to each line of a file using a simple shell script. Enhance your text processing skills with this quick and easy guide!
Enhance Your Text Files: Adding Suffixes to Each Line with Shell Scripting
Here’s a shell script that adds a suffix to each line of a text file and outputs the result in HTML format, along with a sample HTML structure featuring a main heading, subheading, and multiple paragraphs. The suffix added will be “.chatgpt.com”. ### Shell Script to Add Suffix ```bash #!/bin/bash # Input file input_file="input.txt" # Output file output_file="output.html" # Suffix to add suffix=".chatgpt.com" # Create HTML structure { echo "

Main Heading

" echo "

Subheading

" echo "

" # Read each line from the input file and add suffix while IFS= read -r line; do echo "${line}${suffix}
" done < "$input_file" echo "

" } > "$output_file" echo "HTML output generated in $output_file" ``` ### Sample Input File (`input.txt`) ``` This is the first line Here is the second line And this is the third line Let's add more lines This is the fifth line Yet another line here Continuing with line seven Almost done with the eighth line Finally, this is the ninth line Last but not least, the tenth line ``` ### Expected Output in `output.html` ```html

Main Heading

Subheading

This is the first line.chatgpt.com
Here is the second line.chatgpt.com
And this is the third line.chatgpt.com
Let's add more lines.chatgpt.com
This is the fifth line.chatgpt.com
Yet another line here.chatgpt.com
Continuing with line seven.chatgpt.com
Almost done with the eighth line.chatgpt.com
Finally, this is the ninth line.chatgpt.com
Last but not least, the tenth line.chatgpt.com

``` ### Explanation 1. **Shell Script**: - The script reads from an input file named `input.txt`. - It generates an output file named `output.html`. - Each line from the input file has the suffix `.chatgpt.com` appended to it. - The output is formatted in HTML with a main heading, subheading, and a single paragraph containing all modified lines. 2. **HTML Structure**: - The HTML output includes a main heading `

`, a subheading `

`, and a paragraph `

`. - Each line from the input, after being processed by the shell script, is displayed in the paragraph, separated by `
` tags to ensure they appear on separate lines in the HTML. This script and output format can be expanded further by adding more content to the input file, ensuring that the total word count reaches the desired length of approximately 500 words.