Question

Write an awk (nawk) or sed command file that converts a textfile to a html file...

Write an awk (nawk) or sed command file that converts a textfile to a html file (by inserting tags <HTML><BODY><PRE> at the beginning of your existing file: file1.txt and inserting tags </PRE> ></BODY></HTML> at the end of file1.txt)

Sample Run:

awk -f awkfile.txt file1.txt > file1.html

or use

sed –f sedfile.txt file1.txt > file1.html

Sample Output:

Use a browser to show your file1.html

Homework Answers

Answer #1

This script file can be used to convert a text file to html file

#! /bin/bash
 
if [ $# -eq 0 ] ; then
   echo "USAGE: $(basename $0) file1 file2 file3 ..."
   exit 1
fi
 
for file in $* ; do
   html=$(echo $file | sed 's/\.txt$/\.html/i')
 
   echo "<html>" > $html
   echo "   <body>" >> $html
   echo "   <pre>" >> $html
 
   while read line ; do
      echo "$line<br>" >> $html
   done < $file
 
   echo "   </body>" >> $html
   echo "</html>" >> $html
   echo "   </pre>" >> $html
done



This below command will simply convert any html file to text file without using script file

sed 's/<[^>]*>//g ; /^$/d' htmlpage.html > output.txt
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a program in python that takes a txt file and converts it to html
Write a program in python that takes a txt file and converts it to html
UNIX COMMANDS Task B Create a one-line command, using the famous.dat file, to add the word...
UNIX COMMANDS Task B Create a one-line command, using the famous.dat file, to add the word " STREET" to the address, for all who live on 2nd or 3rd. For example: "2nd" becomes "2nd STREET" and "3rd" becomes "3rd STREET". Display only the first 9 lines. Hint: Use 2 sed statements with pipes. Task C Display all lines in famous.dat that end in 0 or 1, and have a 1 in the 3rd from the last column. For example lines...
Write an M-File scripts that converts temperature in degrees Fahrenheit ( °F) to degrees Centigrade (...
Write an M-File scripts that converts temperature in degrees Fahrenheit ( °F) to degrees Centigrade ( °C) by recall the conversion function in (a). Use input and disp commands to display a mix of text and number.
Write Linux command lines to do the following: 1. Create a directory with name “yourName_ID” 2....
Write Linux command lines to do the following: 1. Create a directory with name “yourName_ID” 2. Create a file with name “yourLastName.txt” inside the directory created in step.1 3. Write inside the created file exactly the following content (you may use editors such as vim, pico, ….): Linux Lab Lab. ToDo#1 Summer Semester 2019/2020# 4. Display the first 2 lines of the file. 5. Change the permission of the file to read write and execute for owner, groups and others....
Write UNIX commands to perform the following tasks. Each task must use exactly one line of...
Write UNIX commands to perform the following tasks. Each task must use exactly one line of command. Unless stated otherwise, all files are assumed to be at your current working directory. a) (10 points) Print your current working directory into a file named file1 b) (10 points) Assume that your current working directory is NOT the same as your home directory. Print all file and subdirectory names of your home directory into a file named file2. c) (15 points) Copy...
Following are the most important file management functions available in C. Use any 6 of them...
Following are the most important file management functions available in C. Use any 6 of them in your program and show the output. Function purpose fopen () Creating a file or opening an existing file fclose () Closing a file fprintf () Writing a block of data to a file fscanf () Reading a block data from a file getc () Reads a single character from a file putc () Writes a single character to a file getw () Reads...
Write a python code to print (any given file) file as a csv format by using...
Write a python code to print (any given file) file as a csv format by using MRJob only. code must be able to run stand-alone MRJob application. For submission to your work: Your final hand should be a single file name BDM.py that takes exactly one arguments for the input path. output will be handled through redirection. Sample run: python BDM.py sample.csv > output.csv
Note: Use SPSS to solve the following questions. For every question Write the SPSS command and...
Note: Use SPSS to solve the following questions. For every question Write the SPSS command and then copy and paste the output page here (or in some cases the screenshot of the data view that shows the output). Can I Know also what is the sample file (in SPSS) that we work on? Question : If the probability of finding a defective product of a company’s total products is given as 1 out of hundred, with a sample size of...
PART B- Javascript Using a text editor (VS Code or Notepad) and a web browser, you...
PART B- Javascript Using a text editor (VS Code or Notepad) and a web browser, you will demonstrate how to create an HTML file, externally link a JavaScript file, and write some source code in the JavaScript file. a..Create two blank files to be an HTML file and a JavaScript file. The file names should be partA.html and partA.js. b.. Create a basic HTML webpage structure. c..Link the JavaScript file to the HTML file using the <script> tag. d.. Prompt...
You have one Question, Which have four parts, 1st... PHP scriptIn a HTML document, use PHP...
You have one Question, Which have four parts, 1st... PHP scriptIn a HTML document, use PHP to obtain the following :The user will write a sentence as a value of a predefined variable.The output should look like this :The sentence you entered is :This is my sentenceIt is composed of :• 4 different words• 19 characters (including spaces)Note : Your program should make sure the final output is in lower case with the first letter in upper case. 2nd... PHP...