Shell / sed Program To Remove All C and C++ Comments From Program File

in Categories Academic, Script last updated May 6, 2008

Write the shell / sed program which remove all the comments from a simple C program stored in your current directory. You can assume that the c source code contains only syntactically correct comments:
+ start with // and end with a newline

+ starting with /* and ending */ (can be multiline)

+ nesting of comments is not allowed

Make sure that C source is not changed at all.

How do I use this sed script?

$ ./script.sed < input.c $ ./script.sed < input.c > output.c
$ for c in *.c; do script.sed < $c > /tmp/zyzcc.c; /bin/cp -f /tmp/zyzcc.c $c; done

Sample sed code to remove all comments from sed

Please note that this program is copied from public domain.

Shell Script Searches For A Single Word Pattern Recursively

in Categories Academic last updated May 5, 2008

Shell Script To Display Last Five Lines Of The File

in Categories Academic last updated April 12, 2008

Given the filename by the user as the input, write a shell script to display the last five lines of the file.

Shell Script

Command Line Argument

You can read file name as command line argument:

Shell script to find whether an input number is palindrome or not

in Categories Academic, Shell Math last updated April 12, 2008

A palindrome is a word, phrase, number or other sequence of units that has the property of reading the same in either direction (the adjustment of punctuation and spaces between words is generally permitted). Composing literature in palindromes is an example of constrained writing. The word “palindrome” was coined from Greek roots palin (“back”) and dromos (“way, direction”) by English writer Ben Jonson in the 1600s.

A palindromic number is a number where the digits, with decimal representation usually assumed, are the same read backwards, for example, 58285. They are studied in recreational mathematics where palindromic numbers with special properties are sought. A palindromic prime is a palindromic number that is a prime number.

Shell program to read a number and find the sum of digits

in Categories Academic, Shell Math last updated April 8, 2008

Shell program to read a number and reverse the number

in Categories Academic, Shell Math last updated April 8, 2008

Shell program to calculate the number of digits in a number read from the user

in Categories Academic, Shell Math last updated April 8, 2008

Shell program to read two numbers and display all the odd numbers berween those two number

in Categories Academic, Decision Making last updated April 8, 2008

Shell program to display numbers from 1 to 10

in Categories Academic last updated April 8, 2008