Question: Assignment 2 : sed For this assignment, you will use sed, bash, and some other command - line utilities to create a program for formatting
Assignment : sed
For this assignment, you will use sed, bash, and some other commandline utilities to create a program
for formatting C code. Your program should take a source code file as input and apply the following:
No more than one space between tokens.
No trailing whitespace after a line.
Binary operators should always surrounded by a single space on either side including assignment
and Boolean Only the following operators must be accounted for:
Conditions should not have whitespace immediately inside of the parentheses.
The program should not modify spaces which are leading, expanded tabs
Comments should be left alone. You may assume comments single and multiline will not appear
on lines with source code.
Hint: The above need not be performed in a single pass.
This assignment requires only sed and bash. Do not use awk, Python, or any other languages, utilities,
or programs unless explicitly approved. The assignment is best solved using the specific topics discussed
in class and that you will find in the sed slide deck.
Example
In the code below, underscores represent spaces. Note that there are no changes to comments or
#include preprocessor directives. This file is merely an example; you should test your script against
input files you have formulated yourself, with the aim of developing test cases that cover as many
potential input types, groups, and values as possible.
Input inputProgramc:
author : som estud ent
# include stdio h
intmain
intnumberIn ;
printf Enteranumber : ;
scanf d & numberIn ;
ifnumberIn
addtwo
r e t u r n n u m b e r I n ;
Assignment : sed Page of
elseif numberIn
s ub t r ac t tw o
returnnumberIn ;
r e t u r n n u m b e r I n ;
Output outputProgramc:
author : som estud ent
# include stdio h
intmain
intnumberIn ;
printf Enteranumber : ;
scanf d & numberIn ;
if numberIn
addtwo
r e t u r n n u m b e r I n ;
elseif numberIn
s ub t r ac t tw o
returnnumberIn ;
r e t u r n n u m b e r I n ;
Script Execution
Your program should be invoked through a single bash file see below with the path to the input text file
specified as the first and only argument. The resulting output file should be printed directly to standard
out.
$ bash assignbash pathtoinputfiletxt
Assignment Data
Script Files
Your program should consist of at least two files:
assignbash the main file which is initially invoked
At least one sed file which is used for a sed invocation, run via assignbash. Each sed
invocation should have its own sed file which may contain multiple sed commands.
For example, your submission may include assignbash, commandsed, and commandsed where
the two sed files are used for two corresponding sed invocations within assignbash.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
