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 2: sed
For this assignment, you will use sed, bash, and some other command-line 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 multi-line) 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 pre-processor 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 (inputProgram.c):
1/**
2 author : _____som e_stud ent
3**/
4 # include_< stdio .h >
5
6 int_main ()_{
7____int_numberIn ;
8
9____printf (" Enter_a_number : _") ;
10
11____scanf ("% d ",_ & numberIn ) ; __
12
13____if_(_numberIn_>_10_)_{
14____//____add__two
15________ r e t u r n _ n u m b e r I n _+__2 ;
Assignment 2: sed Page 1 of 3
16____}_else___if____( numberIn <5){
17____//____ s ub t r ac t _ tw o ___
18________return__numberIn_-_2 ;
19
20____ r e t u r n __ n u m b e r I n *2;
21}
Output (outputProgram.c):
1/**
2 author : _____som e_stud ent
3**/
4 # include_< stdio .h >
5
6 int_main ()_{
7____int_numberIn ;
8
9____printf (" Enter_a_number : _") ;
10
11____scanf ("% d ",_ & numberIn ) ;
12
13____if ( numberIn_>_10)_{
14____//____add__two
15________ r e t u r n _ n u m b e r I n _+_2 ;
16____}_else_if ( numberIn_<_5){
17____//____ s ub t r ac t _ tw o ___
18________return_numberIn_-_2 ;
19
20____ r e t u r n _ n u m b e r I n _*_2 ;
21}
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 assign2.bash /path/to/input/file.txt
Assignment Data
Script Files
Your program should consist of at least two files:
assign2.bash the main file which is initially invoked
At least one .sed file which is used for a sed invocation, run via assign2.bash. Each sed
invocation should have its own .sed file which may contain multiple sed commands.
For example, your submission may include assign2.bash, command1.sed, and command2.sed where
the two .sed files are used for two corresponding sed invocations within assign2.bash.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!