Question

In Linux, using sed, make the following changes in a txt file: Deletes trailing white space...

In Linux, using sed, make the following changes in a txt file:

Deletes trailing white space in each line.

Every comma is followed by exactly one space.

Every period is followed by exactly two spaces.

Make the above into a script procedure called rmHTML().

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#scriipt starts here

### rmHTML() is function which takes in filename as pararmeter and
### and removes trailing white space and other changes
rmHTML()
{
filenames=$@
sed -i.bak -e 's/\s*$//g' -e 's/,\s*/, /g' -e 's/\.\s*/. /' $filenames
# -i.bak is backup file
# s/\s*$//g is Deletes trailing white space in each line
# s/,\s*/, /g is Every comma is followed by exactly one space.
# s/\.\s*/. / is Every period is followed by exactly two spaces
}


rmHTML inputFile.txt
echo "content backup is placed at file inputFile.txt.bak"
echo "The file is modified at inputFile.txt"
echo "Content of modified file is shown below: "
cat inputFile.txt

#scriipt ends here

input---file content is shown below:

How are you, seeyou ok
1, 2,3,5 7,abc.cc
uer.u.ier 89
ok now what, see you!!

----------output Changes----

How are you, seeyou ok

1, 2, 3, 5 7, abc. cc
uer. u.ier 89
ok now what, see you!!

Add a comment
Know the answer?
Add Answer to:
In Linux, using sed, make the following changes in a txt file: Deletes trailing white space...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • a) Write a one-line sed command that will replace all multiple spaces in a file called...

    a) Write a one-line sed command that will replace all multiple spaces in a file called names.txt (this is an arbitrary file that you may create yourself) by only one space. b) Consider the following file called system.txt: 1  2  3  4 5  6  7  8 9  He 11 Hg Ts H  15 Be 17 Mc Li 20 Write a one-line sed command that replaces the second number in every line with the string “system”, without the quotes. For example,...

  • Consider an input file A2.txt. Each line of A2.txt consists of two numbers separated by space....

    Consider an input file A2.txt. Each line of A2.txt consists of two numbers separated by space. Write a C++ program that reads the two numbers from each line and prints how many numbers are prime between them. Your program must have a user defined function that takes one number as input parameter and detects whether its prime or not. Show your output in a file named B2.txt using the following format: Sample Input: 3 17 42 91 Sample Output: 6...

  • This is done in Linux terminal. Modify the .bashrc file using command line which would add...

    This is done in Linux terminal. Modify the .bashrc file using command line which would add the following functionality to your shell upon opening a new terminal: 1. Alias called “fc” (short for “folder contents) invoking the command “ls -lah”B. Welcome message “This is demo number 7” C. Variable “semester” being equal to “Winter 2020” and print the value on screen 2. Create any directory of your choice and add it to PATH variable. 3. Show an example of local...

  • There is a file called mat2.txt in our files area under the Assignments folder. Download it...

    There is a file called mat2.txt in our files area under the Assignments folder. Download it and save it in the same folder where this Matlab file (HW08_02.m) is saved. It may be worth opening that text file to see how it is set out. Note well, however, that the file might have a different number of lines and different number of numbers on each line. Write a Matlab program that does the following: Prompt the user for an input...

  • Answer the following questions using linux 1) Write a Python script so that a file whoComesForDinner.txt...

    Answer the following questions using linux 1) Write a Python script so that a file whoComesForDinner.txt formatted like this:      Tuesday we have Joe McHungry and Paul McHungry Wednesday we have Cindy Johnston and Paul Paulsen Thursday we have Amin Mirzaei and Atefeh Mirzaei gets turned into that: The McHungry on Tuesday Cindy and Paul on Wednesday The Mirzaei on Thursday 2)Write a script that takes as argument a port number. It returns the next port that is not assigned to...

  • USING MATLAB SOFTWARE writing a script 2) A file called "hightemp.txt" was created some time ago...

    USING MATLAB SOFTWARE writing a script 2) A file called "hightemp.txt" was created some time ago which stores, on every line, a year followed by the high temperature at a specific location for each month of that year. For example, the file might look like this: 89 42 49 55 72 63 68 77 82 76 67 90 45 50 56 59 62 68 75 77 75 66 91 44 43 60 60 60 65 69 74 70 70 As...

  • Write a new program (hw6-pr1) meeting at least the following minimum requirements: Opens the text version...

    Write a new program (hw6-pr1) meeting at least the following minimum requirements: Opens the text version of this file (hw6-Spring2017.txt) and searches thru the file for the first occurrence of each of the 26 uppercase characters of the alphabet (A-Z), then each the 10 digits (0-9), and finally each of the 26 lowercase characters of the alphabet (a-z). As it finds each of these characters it should also record its position in the file (assume the first character in the...

  • PLEASE DO IT IN PYTHON, THANK YOU! CSV file: This is a file containing plain text...

    PLEASE DO IT IN PYTHON, THANK YOU! CSV file: This is a file containing plain text where each line in the file represents one record of information, and each piece of info in the record is separated by a single comma. Luckily the values won't ever contain commas themselves for this project. But they might start or end with non visible characters (e.g. space, tab). Thus, you must remove the leading and trailing spaces when you store the data in...

  • This is being done in c using command line in Linux 1.1 llist: Linked list Write...

    This is being done in c using command line in Linux 1.1 llist: Linked list Write a program llist that maintains and manipulates a sorted linked list of integers according to instructions received from standard inpu. The linked list is maintained in order, meaning that each integer will be larger than the one preceeding it. 1list maintains a linked list containing zero or more integers, ordered from least to greatest llist will need to allocate space for new nodes as...

  • A. File I/O using C library functions File I/O in C is achieved using a file...

    A. File I/O using C library functions File I/O in C is achieved using a file pointer to access or modify files. Processing files in C is a four-step process: o Declare a file pointer. o Open the desired file using the pointer. o Read from or write to the file and finally, o Close the file. FILE is a structure defined in <stdio.h>. Files can be opened using the fopen() function. This function takes two arguments, the filename and...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT