Run this script as follows:
cat file.c | ./script.sh
sample file.c:
#include<stdio.h> /* This is a test program * Version 1.0 * */ int main(){ printf("This is a test"); /* now exit */ }
Sample output:
#include<stdio.h> int main(){ printf("This is a test"); }
Sed Script
#!/bin/sed -f
# Simple Sed Program to remove all comments from c program
# --------------------------------------------------------------------
# This is a free shell script under GNU GPL version 2.0 or above
# Copyright (C) 2005 nixCraft project.
# Feedback/comment/suggestions : http://cyberciti.biz/fb/
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# if no /* get next
//*/!b
# here we've got an /*, append lines until get the corresponding
# */
/*//!{
N
bx
}
# delete /*...*/
s//*.**///
Sign up for our daily email newsletter:
You must log in to post a comment.